php和url重写不能一起工作



我有一个RewriteRule,它可以从每个URL的末尾删除.php,在一起编写时效果很好。我有另一个RewriteRule,它重写了我的URL,使我能够键入example.com/page/25/Dominic而不是example.com/page.php?id=25&name=Dominic。不过,这两个RewriteRule不会同时工作。

我都试过了,他们确实独立工作。

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteBase /
Options -MultiViews
RewriteRule ^page/([0-9]+)/([0-9a-zA-Z_-]+) page.php?id=$1&name=$2 [NC,L]
#This one breaks the page and causes a 500 internal server error if the Rule above is used as well. 
#RewriteRule ^(.*)$ $1.php [NC] [QSA] [L]

example.com/home应该在没有.php扩展的情况下工作,并且page.php的URL重写也应该工作。

我在编辑.htaccess时遇到了完全相同的问题。我认为这与你的服务器将/page/作为一个目录来查找有关,而这个目录实际上并不存在于你的服务器上(它只是通过重写规则或类似规则创建的虚拟目录(。

只需更改page.php的名称(blogpage.php,userpage.php,…(,它就可以工作了。

编辑:

Options All -Indexes +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*[^/])/?$ /$1.php [L,QSA]
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^page/([0-9]+)/(.+)$ pages.php?id=$1&name=$2 [QSA,NC,L]

最新更新