Htaccess规则不适用

我在我的htaccess文件中有以下规则来删除.php扩展名,并做一个301redirect到无扩展名的URL:

# To remove .php extension RewriteCond %{THE_REQUEST} ^[AZ]{3,}\ (.*)\.php [NC] RewriteRule ^ %1 [R=301,L] # To check whether the file exists then set it back internally RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^.*$ $0.php [L] 

我想在PHP文件上应用以下规则:

 RewriteRule ^test/([0-9]+)$ test.php?id=$1 [L] 

上述规则导致500内部服务器错误。 如果我删除了第一组规则,则第二条规则再次运行。 所以,这两套规则都有一些冲突。

问题是规则的顺序:)

当我改变如下的顺序时,一切正常:

 RewriteRule ^test/([0-9]+)$ test.php?id=$1 [L] # To remove .php extension RewriteCond %{THE_REQUEST} ^[AZ]{3,}\ (.*)\.php [NC] RewriteRule ^ %1 [R=301,L] # To check whether the file exists then set it back internally RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^.*$ $0.php [L]=