即使使用 L 标志,mod_rewrite 也会循环 [英] mod_rewrite loops even with L flag

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

问题描述

我在重写 fastcgi 调度程序的 URL 时遇到问题.如果我只离开:

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

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

我预计 L(最后一条规则)只会导致一次重写.相反,它一直在 dispatch.fcgi 前面加上,直到 apache 报告错误.

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]

但是多次重写的原因是什么?L 是否做了一些我认为没有的事情?

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 文件中起作用.它告诉 rewrite 模块 跳过该特定 .htaccess 文件中的所有以下规则.它完成它的工作,Apache 重写 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重新开始.

这是上面发生的事情,^(.*)$总是匹配当前的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 文件属性测试(如提问者所述)将解决问题,因为 url 将匹配一个真实的文件名:

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.

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

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