Bug 54556 - New flag to add default rule in rule chain
Summary: New flag to add default rule in rule chain
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_rewrite (show other bugs)
Version: 2.4.3
Hardware: All All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
Keywords: PatchAvailable
Depends on:
Reported: 2013-02-13 12:16 UTC by David Saez
Modified: 2013-02-13 12:18 UTC (History)
0 users

Patch that add CDEF new RewriteRule flag (2.74 KB, application/octet-stream)
2013-02-13 12:16 UTC, David Saez
Patch that add CDEF new RewriteRule flag (2.74 KB, patch)
2013-02-13 12:18 UTC, David Saez
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Saez 2013-02-13 12:16:47 UTC
Created attachment 29946 [details]
Patch that add CDEF new RewriteRule flag

The CDEF flag marks the rule as the default rule for a rule chain.

If the rule does not match it acts as if it has the CHAIN flag and makes the engine skip all chained rules.

If the rule matches the result is saved as the default result for the rule chain and the rule is ignored as if it didn't match, then engine continues testing rules in the chain. If one of the chain rules matches then the default is discarded and the matching rule is used. If none of the chained rules matches, then the default is used.

It converts the rule tagged with CDEF as a sort of RewriteCond that can be used with more than one rule and provides a default result, but it also actually prevents the chained rules to be tested if it does not match:

For example:

RewriteRule ^example$	/index.php?action=foo [L,NS,QSA]
RewriteRule ^(login|lostpw|logout|expired)$	/index.php?page=$1 [L,NS,QSA]
RewriteRule ^([a-z]+)$ /index.php?section=$1 [L,NS,QSA]

The first two rules are exceptions to the last one and in a normal setup a uri that does not match any of this rules will triger a test on every rule. Using CDEF it can be written that way;

RewriteRule ^([a-z]+)$ /index.php?section=$1 [L,NS,QSA,CDEF]
RewriteRule ^example$	/index.php?action=foo [L,NS,QSA,C]
RewriteRule ^(login|lostpw|logout|expired)$	/index.php?page=$1 [L,NS,QSA]

this way non-matching uri's will only trigger a test on the first rule and all the other two will be skipped
Comment 1 David Saez 2013-02-13 12:18:34 UTC
Created attachment 29947 [details]
Patch that add CDEF new RewriteRule flag

is the same patch, is just that submitting it when opening the request does not allow to see the diff