我有一个网站,它包含没有变量的静态页面(例如: about.php)和一些动态页面(例如: searchresults.php?a=1&b=2)。
现在,我的.htaccess允许静态页面显示,而不是动态页面。然而,为了使动态页面正常工作,我所做的一切都破坏了静态页面的干净URL。
RewriteEngine On
DirectoryIndex index.php index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
RewriteRule ^([^\.]+)$ $1.html [NC,L]我希望最终结果如下:
http://example.com/about.php -> http://example.com/about和
http://example.com/searchresults.php?a=1&b=2 -> http://example.com/searchresults/1/2我想要做的事有可能吗?
发布于 2015-06-01 06:00:48
是的,有可能。
首先,您需要更改您的规则以删除扩展。目前,您有两个规则匹配任何东西(意味着第二个规则永远不会触发),而第二个规则没有条件。
其次,需要显式地指定搜索规则。
您的.htaccess文件现在应该如下所示:
RewriteEngine on
# Rewrite the search page
RewriteRule ^searchresults/([^/]+)/([^/]+)/?$ searchresults.php?a=$1&b=$2 [QSA,L]
# Allow requests without php/html extensions
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^\.]+)$ $1.html [L]发布于 2015-06-01 06:08:32
为您的htaccess文件尝试下面的代码行。
RewriteEngine on
RewriteRule aboutus/$ about.php [NC,L,QSA]
RewriteRule searchresults/(.*)/(.*)/$ searchresults.php?a=$1 & b=$2 [NC,L,QSA]https://stackoverflow.com/questions/30566451
复制相似问题