只有第一个RewriteRile工作在.htaccess文件中

时间:2015-03-01 16:30:14

标签: regex apache .htaccess mod-rewrite

我的htaccess文件中有2个重写规则,但只有第一个正在工作

删除.php

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

编辑我的网址blog-detailed.php?id = 1到blog / 1

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^blog/([0-9]+)/?$ blog-detailed.php?id=$1

1 个答案:

答案 0 :(得分:2)

按此顺序制定规则:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^blog/([0-9]+)/?$ blog-detailed.php?id=$1 [L,QSA]

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