htaccess:重写冲突 - 简单的问题

发布于 2024-09-17 18:58:57 字数 125 浏览 3 评论 0原文

这一行肯定会引起一点冲突,因为它会尝试重写目标本身:

RewriteRule ^/(.*)$ page.php?q=$1 [L,NC]

现在,我该如何防止这种情况发生?

This row will certainly cause a little collision as it will try to rewrite the goal itself:

RewriteRule ^/(.*)$ page.php?q=$1 [L,NC]

Now, how do I prevent this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

远昼 2024-09-24 18:58:57

只需添加一个条件,即匹配的字符串与目标字符串不同:

RewriteCond $1 !=page.php
RewriteRule ^/(.*)$ page.php?q=$1 [L]

这里,RewriteCond 中的 != 表示否定的字典比较,而不是隐含的正则表达式比较。

Just add a condition that the matched string is not the same as the destination:

RewriteCond $1 !=page.php
RewriteRule ^/(.*)$ page.php?q=$1 [L]

Here the != in RewriteCond indicates a negated lexicographic comparison instead of the implied regular expression comparison.

寄与心 2024-09-24 18:58:57

使用条件重写:

RewriteCond %{REQUEST_URI} !^page.php?
RewriteRule ^/(.*)$ page.php?q=$1 [L,NC]

Using a conditional Rewrite:

RewriteCond %{REQUEST_URI} !^page.php?
RewriteRule ^/(.*)$ page.php?q=$1 [L,NC]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文