Bug 54556

Summary: New flag to add default rule in rule chain
Product: Apache httpd-2 Reporter: David Saez <david>
Component: mod_rewriteAssignee: 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 CDEF new RewriteRule flag
Patch that add CDEF new RewriteRule flag

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