httpd-bugs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 54543] Compile regex only when need
Date Wed, 13 Feb 2013 09:49:30 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=54543

--- Comment #1 from David Saez <david@ols.es> ---
Created attachment 29945
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=29945&action=edit
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

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: bugs-unsubscribe@httpd.apache.org
For additional commands, e-mail: bugs-help@httpd.apache.org


Mime
View raw message