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?
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?
this is not a question regarding overlapping rules etc, for this question assume that all the rules are [L] and non-overlapping.
so,
should the most used rules be as close to the top as possible, while the less used ones near the bottom?
thanks!
From the documentation for RewriteRule:
http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule
The order in which these rules are defined is important – this is the order in which they will be applied at run-time.
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 – Stop the rewriting process immediately and don’t apply any more rules