为什么 [L] 标志在我的 .htaccess 文件中不起作用?

发布于 2024-09-01 06:04:18 字数 378 浏览 1 评论 0原文

规则如下:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回眸一遍 2024-09-08 06:04:18

您可以将

^[\w\W]*$ 更改为 ^[\w\W]+$^.+$

You could change

^[\w\W]*$ to ^[\w\W]+$ or ^.+$

递刀给你 2024-09-08 06:04:18

如果最后一行是包罗万象的,只需执行 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]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文