Apache - 重写规则混乱
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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 theRedirect
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 plainRedirect
directive is just an easy way of achieving the simpler functionality ofRewriteRule
.你的规则不会跳来跳去,事实上,L 标志意味着最后一个规则,所以当一个规则被触发时,文件将停止被读取。
your rules arent jumping around, in fact, the L flag means LAST rule, so when one is triggered, the file stops being read.