mod_rewrite的循环,甚至以L标志 [英] mod_rewrite loops even with L flag

查看:87
本文介绍了mod_rewrite的循环,甚至以L标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,重写一个URL到FastCGI的调度。如果我只离开:

I've got a problem with rewriting a URL to a fastcgi dispatcher. If I leave only:

RewriteRule ^(.*)$ dispatch.fcgi/$1 [L,QSA]

我的预期(最后一个规则),使只有一个重写,相反,它使prepending dispatch.fcgi 直到阿帕奇报告错误。

I expected L (last rule) to cause only a single rewrite. Instead, it keeps prepending dispatch.fcgi until apache reports an error.

我知道这是可以固定的:

I know it can be fixed with:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L,QSA]

但是,什么是多个重写的原因吗?请问做别的事情比我想象的那样?

But what is the reason for multiple rewrites? Does L do something else than I think it does?

推荐答案

我知道这是一个老问题,但给别人搜索的真正的答案,在这里它是:

I know it's an old question, but to others searching for the REAL answer, here it is:

[L] 标记的 DOES 的.htaccess 文件的工作。它告诉重写模块跳过所有的下列规则在那个特定的的.htaccess 文件。它的工作,阿帕奇重写的URL,并退出的.htaccess 文件。

The [L] flag DOES work in .htaccess files. It tells the rewrite module to skip all of the following rules in that particular .htaccess file. It does its job, Apache rewrites the url and exits the .htaccess file.

然而,在年底的的.htaccess 文件如果请求的URL被改写,整个URL匹配过程中再次与新的网址

这是上面发生了什么, ^(。*)$ 总是匹配当前的URL,它会导致一个无限循环,只有 maxredirect 改写选项(默认10)停止。

This is what happens above, ^(.*)$ will always match the current url, it causes an infinite loop, only the maxredirect rewrite option (10 by default) stops it.

! - ˚F文件属性测试(由提问者提到的)将解决问题后,因为该网址将匹配一个真实的文件名:

The !-f file attribute test (as mentioned by the questioner) would solve the problem, since the url will match a real filename:

的RewriteCond%{} REQUEST_FILENAME!-f

RewriteCond %{REQUEST_FILENAME} !-f

重写规则^(。*)$ dispatch.fcgi / $ 1 [L,QSA]

RewriteRule ^(.*)$ dispatch.fcgi/$1 [L,QSA]

现在,如果我们要求 http://example.com/toappend 的.htaccess 它改写为 dispatch.fcgi / toappend 没有重写循环会发生。

now, if we request http://example.com/toappend, .htaccess rewrites it to dispatch.fcgi/toappend and no rewrite loop will happen.

这篇关于mod_rewrite的循环,甚至以L标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆