Apache - 重写规则混乱

发布于 2024-08-04 00:32:03 字数 814 浏览 8 评论 0原文

Redirect 301 /resort.php/FOO/BAR http://www.sitename.com.com/index.php
RewriteRule ^/direct/(.*) /direct/$1 [QSA,L] # access non i18n files directly
RewriteRule ^/([a-z]{2}\/.*)        /$1 [QSA,L] #any language subdirectory should be left alone
RewriteRule ^/(.*\/$)               /en/$1index.php [QSA,L] #fix for links ending in /
RewriteRule ^/(.*\.php)             /en/$1 [QSA,L]  #any php file with no language subdirectory redirects to the default language

为什么第一个重定向 301 不去主页的原因是什么?当我将其替换为..时,

RewriteRule ^/resort.php(.*) http://www.sitename.com/index.php [R=301,L]

它开始工作。我确信这是因为我有一堆规则,它会转到一个规则并跳转到另一个规则,但我有点迷失了,也许一位大师可以更清楚地解释这一点。

我的目录结构是这样的:

/en/index.php
/direct/

根目录中没有 /index.php ,我最初将其重定向到 en 。

Redirect 301 /resort.php/FOO/BAR http://www.sitename.com.com/index.php
RewriteRule ^/direct/(.*) /direct/$1 [QSA,L] # access non i18n files directly
RewriteRule ^/([a-z]{2}\/.*)        /$1 [QSA,L] #any language subdirectory should be left alone
RewriteRule ^/(.*\/$)               /en/$1index.php [QSA,L] #fix for links ending in /
RewriteRule ^/(.*\.php)             /en/$1 [QSA,L]  #any php file with no language subdirectory redirects to the default language

What's the explanation for why the first Redirect 301 isn't going to the homepage? When I replace it with..

RewriteRule ^/resort.php(.*) http://www.sitename.com/index.php [R=301,L]

It starts working. I'm sure it's because I have a bunch of rules and it goes to one and jumps to the other but I'm kinda lost and maybe a guru could explain this more clearly.

My directory structure is like so:

/en/index.php
/direct/

There is no /index.php in the root, I'm redirecting it to en initially.

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

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

发布评论

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

评论(2

只有影子陪我不离不弃 2024-08-11 00:32:03

Redirect 指令与 mod_rewrite 发生了争执。后者相当激进,可能会覆盖通过 Redirect 指令在响应上设置的重定向 HTTP 标头。

您已经找到了解决方案 - 使用 RewriteRule 执行重定向。 [L] 标志的意思是“最后一条规则 - 不再处理”,这就是防止规则相互干扰的方法。简单的 Redirect 指令只是实现 RewriteRule 更简单功能的一种简单方法。

The Redirect directive is getting into a bun-fight with mod_rewrite. The latter is quite aggressive, and is probably over-writing the redirect HTTP header set on the response by the Redirect directive.

You've already found the solution - use a RewriteRule to perform the redirect. The [L] flag means "last rule - don't process any more", which is how you prevent the rules from interfering with each other. The plain Redirect directive is just an easy way of achieving the simpler functionality of RewriteRule.

娇俏 2024-08-11 00:32:03
RewriteRule /resort.php/FOO/BAR http://www.sitename.com.com/index.php [R=P, L]

你的规则不会跳来跳去,事实上,L 标志意味着最后一个规则,所以当一个规则被触发时,文件将停止被读取。

RewriteRule /resort.php/FOO/BAR http://www.sitename.com.com/index.php [R=P, L]

your rules arent jumping around, in fact, the L flag means LAST rule, so when one is triggered, the file stops being read.

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