When a RewriteRule is executed by MOD_Rewrite will all the MOD_Rewrite rules be executed again for the newly generated request? Specifically in the following example, will this cause a loop?
当MOD_Rewrite执行RewriteRule时,是否会为新生成的请求再次执行所有MOD_Rewrite规则?具体在以下示例中,这会导致循环吗?
RewriteCond Host: (?:www\.)?mysite\.com
RewriteRule ^(.*)$ $1 [QSA,L]
1 个解决方案
#1
3
In your case, it won't at any rate do a loop. You have the "L" switch on, fixing that particular rule as the last one.
在你的情况下,它无论如何都不会循环。您打开了“L”开关,将该特定规则固定为最后一个。
Further, you have to explicitly force the next iteration by using the "N" or "NS" switches, or it will just move through your rule file and stop with the last rule that matches. From the docs:
此外,您必须使用“N”或“NS”开关显式强制执行下一次迭代,否则它将仅移动您的规则文件并停止使用匹配的最后一个规则。来自文档:
N (Next iteration)
N(下一次迭代)
Forces rewriting engine to modify rule's target and restart rules checking from the beginning (all modifications are saved). Number of restarts is limited by the value specified in the RepeatLimit directive. If this number is exceeded N flag will be simply ignored.
强制重写引擎以修改规则的目标并从头开始重新启动规则检查(保存所有修改)。重启次数受RepeatLimit指令中指定的值的限制。如果超过此数字,则将忽略N标志。
NS (Next iteration of the same rule)
NS(同一规则的下一次迭代)
Works like the N flag but restarts rules processing from the same rule (i.e. forces repeat of the rule application). Maximum number of a single rule iterations is given by the RepeatLimit directive. But a number of a single rule repeats does not count for the global number of repeats (i.e. repeats limit for a number of iterations caused by N flag is independent of a number of repeats caused by NS).
像N标志一样工作,但重新启动来自同一规则的规则处理(即强制重复规则应用程序)。 RepeatLimit指令给出了单个规则迭代的最大数量。但是,多个单一规则重复不计入全局重复次数(即,由N标志引起的多次迭代的重复限制与由NS引起的重复次数无关)。
#1
3
In your case, it won't at any rate do a loop. You have the "L" switch on, fixing that particular rule as the last one.
在你的情况下,它无论如何都不会循环。您打开了“L”开关,将该特定规则固定为最后一个。
Further, you have to explicitly force the next iteration by using the "N" or "NS" switches, or it will just move through your rule file and stop with the last rule that matches. From the docs:
此外,您必须使用“N”或“NS”开关显式强制执行下一次迭代,否则它将仅移动您的规则文件并停止使用匹配的最后一个规则。来自文档:
N (Next iteration)
N(下一次迭代)
Forces rewriting engine to modify rule's target and restart rules checking from the beginning (all modifications are saved). Number of restarts is limited by the value specified in the RepeatLimit directive. If this number is exceeded N flag will be simply ignored.
强制重写引擎以修改规则的目标并从头开始重新启动规则检查(保存所有修改)。重启次数受RepeatLimit指令中指定的值的限制。如果超过此数字,则将忽略N标志。
NS (Next iteration of the same rule)
NS(同一规则的下一次迭代)
Works like the N flag but restarts rules processing from the same rule (i.e. forces repeat of the rule application). Maximum number of a single rule iterations is given by the RepeatLimit directive. But a number of a single rule repeats does not count for the global number of repeats (i.e. repeats limit for a number of iterations caused by N flag is independent of a number of repeats caused by NS).
像N标志一样工作,但重新启动来自同一规则的规则处理(即强制重复规则应用程序)。 RepeatLimit指令给出了单个规则迭代的最大数量。但是,多个单一规则重复不计入全局重复次数(即,由N标志引起的多次迭代的重复限制与由NS引起的重复次数无关)。