.htaccess mod_rewrite删除.php扩展名,但保留URLpath

我目前有正确的PHP脚本,被调用像这样:

  • www.example.com/user.php/paul
  • www.example.com/tag.php/food

我很难让.htaccess重写正确。 我试图达到这个目的:

  • www.example.com/user/paul
  • www.example.com/tag/food

到目前为止,我可以把它redirect/用户到/user.php,但/ paul丢失; 打破我的脚本。

我现在的.htaccess看起来像这样:

RewriteEngine On RewriteCond %{THE_REQUEST} ^GET\ /([^.\ ]+\.)+php(\?[^\ ]*)?\ HTTP RewriteRule ^(.+)\.php$ http://www.example.com/$1 [R=301,L] RewriteRule ^([^/]+/)*index/?$ http://www.example.com/$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)/$ http://www.example.com/$1 [R=301,L] RewriteCond $1 !^([^.]+\.)+([a-z0-9]+)$ [NC] RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.*[^/])$ /$1.php [L] 

请帮忙。 谢谢! 保罗

 RewriteRule ^(.+)\.php$ http://www.example.com/$1 [R=301,L] 

应该看起来像:

 RewriteRule ^(.+)\.php/(.+)$ http://www.example.com/$1/$2 [R=301,L] 

括号中的项目可以在目标中被引用为每个正则expression式的$ N。