删除扩展的Tricky Rewrite规则

时间:2014-03-22 18:31:54

标签: php apache .htaccess mod-rewrite rewrite

我有以下删除php扩展的规则

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ en/$1.php [NC,L]

现在有了这些规则,当我访问domain.com/abc时,它可以工作。但问题是,当我手动访问domain.com/abc.php时,它也有效。

我想要的是domain.com/abc.php也应该重定向到domain.com/abc。

我怎样才能做到这一点?

简而言之,无论如何我想删除php扩展。

1 个答案:

答案 0 :(得分:0)

您可以添加规则,它会将所有* .php重定向到没有扩展名的uri-s:

RewriteRule ^(.*).php$ /$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ en/$1.php [NC,L]
相关问题