Summary: | Compile regex only when need | ||
---|---|---|---|
Product: | Apache httpd-2 | Reporter: | David Saez <david> |
Component: | mod_rewrite | Assignee: | Apache HTTPD Bugs Mailing List <bugs> |
Status: | NEW --- | ||
Severity: | enhancement | Keywords: | PatchAvailable |
Priority: | P2 | ||
Version: | 2.4.3 | ||
Target Milestone: | --- | ||
Hardware: | All | ||
OS: | All | ||
Attachments: | Patch that add NPC new RewriteRule flag |
Description
David Saez
2013-02-10 17:20:33 UTC
Created attachment 29945 [details]
Patch that add NPC new RewriteRule flag
When a RewriteRule has the NPC flag the rule will not be regex-compiled until the rule needs to be applied.
This flag only have sense and will only work for rules inside .htaccess files. Also the affected rule will be compiled each time is need so it should not be applied to rules that could be re-evaluated on the same request, usually this means that it should only be used when you are sure that the rule will not be evaluated again in the same request.
for example, if we are using some kind of php based CMS that resides on the root of the server and handles dynamic requests through index.php and uses SEO url's using mod_rewrite in a .htaccess file like this:
# avoid applying more rules to static content
RewriteRule ^(css|js|i)/.+ - [L,QSA]
# dinamic content
RewriteRule ^([a-z]+)/([0-9]+)$ /index.php?section=$1&id=$2 [END,NS,QSA]
# and a lot of similar rules ...
Now, all rules in the .htaccess file are always compiled, even for static content requests. We can avoid this and even avoid in many cases having to compile all rules for dinamic content using the NPC flag:
# avoid applying any rule to static content
RewriteRule ^(css|js|i)/.+ - [L,QSA]
# dinamic content
RewriteRule ^([a-z]+)/([0-9]+)$ /index.php?section=$1&id=$2 [END,NS,QSA,NPC]
in this case for static content matched by the first rule no other rule having NPC will be compiled thus saving the time need for regex compilation
|