我将如何编写一个 RewriteRule 来对一个文件进行例外处理
目前我的 .htaccess 文件中有这样的内容:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)\.html$ index.php?pagename=$1&%{QUERY_STRING}
html 文件名被重写为页面名查询字符串。
然而,我试图允许访问一个特定的静态 html 文件,因此我需要以某种方式覆盖规则或例外。
谢谢你的帮助。
I currently have this in my .htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*)\.html$ index.php?pagename=$1&%{QUERY_STRING}
The the html file name is rewritten to the pagename query string.
However I'm trying to allow access to one particular static html file, so somehow I need to overwrite the rule or make an exception.
Thanks for you help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有必要自行附加
QUERY_STRING
;如果没有的话,你会留下一个杂散的&
,并且 mod_rewrite 已经有一个工具可以做得更好:RewriteRule ^(.*)\.html$ index.php?pagename=$1 [QSA]
您可以使用前面的
RewriteCond
来控制RewriteRule
。例如:RewriteCond %{REQUEST_URI} !^/staticpage.html$
RewriteRule ^(.*)\.html$ index.php?pagename=$1 [QSA]
另一个有用的模式是
RewriteCond %{REQUEST_FILENAME} !-f
只要 URL 与文档根目录中的现有常规文件相匹配,就会绕过以下RewriteRule
任何。No point appending
QUERY_STRING
yourself; you'll leave a stray&
if there isn't any, and mod_rewrite already has a tool to do it better:RewriteRule ^(.*)\.html$ index.php?pagename=$1 [QSA]
You can control a
RewriteRule
with aRewriteCond
that precedes it. For example:RewriteCond %{REQUEST_URI} !^/staticpage.html$
RewriteRule ^(.*)\.html$ index.php?pagename=$1 [QSA]
Another useful pattern is
RewriteCond %{REQUEST_FILENAME} !-f
which will bypass the followingRewriteRule
any time that the URL would have matched an existing regular file in the docroot.