使用 apache mod_rewrite 时重写规则的顺序对性能的影响 [英] performance impact of order of rewrite rules when using apache mod_rewrite
问题描述
虽然我读过 mod_rewrite 处理你提供给它的各种重写规则的有时不明显的方式"(例如:首先阅读 RewriteRule,然后返回检查 RewriteCond),但是:
while i have read about the 'sometimes un-obvious way' that mod_rewrite handles the various rewrite rules you feed it (eg: first reading RewriteRule, then going back to check RewriteCond), but:
就性能而言,规则的顺序重要吗?
as far as performance is concerned, does the order of the rules matter?
apache 是否以自上而下"的方式处理它们?这意味着最常用的规则在技术上应该尽可能靠近列表的顶部?
does apache process them in a 'top down' way? meaning that the most used rules should technically be as close to the top of the list as possible?
这不是关于重叠规则等的问题,因为这个问题假设所有规则都是 [L] 并且不重叠.
this is not a question regarding overlapping rules etc, for this question assume that all the rules are [L] and non-overlapping.
所以,
最常用的规则应该尽可能靠近顶部,而较少使用的规则靠近底部吗?
should the most used rules be as close to the top as possible, while the less used ones near the bottom?
谢谢!
推荐答案
来自 RewriteRule 的文档:
From the documentation for RewriteRule:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
定义这些规则的顺序很重要 - 这是它们在运行时应用的顺序.
因此,如果您将常用的重写规则放在顶部,并尽可能用 L 标志标记它们,它就不会处理其余规则,并且您将拥有一个优化的配置:
So if you put your common rewrite rules at the top, and whenever possible mark them with the L flag, it won't process the rest of the rules, and you'll have an optimized configuration:
last|L - 立即停止重写过程,不再应用任何规则
这篇关于使用 apache mod_rewrite 时重写规则的顺序对性能的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!