重写规则问题:.htaccess

时间:2014-05-28 07:02:26

标签: php apache .htaccess url-rewriting

我想让这个网址干净: news.php?后= 13 但是当我试图使用这个RewriteRule:


    RewriteRule ^(news)\/([0-9]+)\/?$ news.php?post=$2

它只显示新闻页面,没有帖子内容。 在过去的两天里,它一直困扰着我,我无法弄明白。有人可以帮我这个吗?

这是整个Htaccess


    RewriteEngine on 

    RewriteRule ^(news)\/([0-9]+)\/?$ news.php?post=$1
    RewriteRule ^(verify)/(.*)/([a-zA-Z0-9_-]+)$ validate_account.php?usr=$2&hash=$3 [QSA,L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php

3 个答案:

答案 0 :(得分:1)

RewriteRule ^(news)\/([0-9]+)\/?$ news.php?post=$2

使用$1

答案 1 :(得分:1)

试试这个配置:

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f

RewriteRule ^news/([0-9]+)\/?$ news.php?post=$1
RewriteRule ^verify/(.*)/([a-zA-Z0-9_-]+)$ validate_account.php?usr=$1&hash=$2 [QSA,L]
RewriteRule ^(.*)$ $1.php

答案 2 :(得分:0)

试试这个方法:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f

RewriteRule ^news/([0-9]+)\/?$ news.php?post=$1