为什么 [L] 标志在我的 .htaccess 文件中不起作用?
规则如下:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ index.php?action=home [L]
RewriteRule ^[\w\W]*$ error.php [L]
当页面与第一个页面匹配时,它应该忽略任何其他进一步的规则。然而访问 /
会导致 error.php
被调用。注释掉第二条规则可以按预期工作 - 页面重定向到 index.php
。
我做错了什么?
另外:有没有更好的方法来编写最后一行?这基本上是一个包罗万象的东西。
Here are the rules:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ index.php?action=home [L]
RewriteRule ^[\w\W]*$ error.php [L]
When a page matches the first one, it is supposed to ignore any other further rules. Yet accessing /
results in error.php
being invoked. Commenting out the second rule works as intended - the page redirects to index.php
.
What am I doing wrong?
Also: is there a better way to write the last line? It's basically a catch-all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将
^[\w\W]*$
更改为^[\w\W]+$
或^.+$
You could change
^[\w\W]*$
to^[\w\W]+$
or^.+$
如果最后一行是包罗万象的,只需执行
RewriteRule ^.*$ error.php [L]
当您发送
/
因为您的规则规定“无任何内容”,并且您正在发送/
。尝试将规则更改为
RewriteRule ^/$ index.php?action=home [L]
If the last line is a catch-all, just do
RewriteRule ^.*$ error.php [L]
Your first line might be erroring out when you send a request for
/
because your rule is saying "nothing" and you are sending/
.Try changing your rule to
RewriteRule ^/$ index.php?action=home [L]