Bug 41412

Summary: RewriteRule Skip should take negative arguments
Product: Apache httpd-2 Reporter: Csaba Gabor <csaba>
Component: mod_rewriteAssignee: Apache HTTPD Bugs Mailing List <bugs>
Status: NEW ---    
Severity: enhancement Keywords: PatchAvailable
Priority: P2    
Version: 2.5-HEAD   
Target Milestone: ---   
Hardware: Other   
OS: All   
Attachments: proposed enhancement
proposed enhancement

Description Csaba Gabor 2007-01-19 06:11:11 UTC
RewriteRule's skip flag [S=#] is a relative goto.  It would be very nice to have
the possibility of negative arguments for it.  So [S=1] means skip the next rule
(already exists), [S=0] means use the next rule (a no-op in other words), [S=-1]
means loop/reevaluate this rule, [S=-2] means goto the previous rule, etc., and
[N] means goto the first rule (already exists).  This would cut out a possibly
large amount of unnecessary testing.

Here's an actual use possibility:
# Deepest directory finder: initialization
# At the end, Pfx will have the shallowest non directory
RewriteRule ^(/[^/]*)(.*)$ - [E=Pfx:$1,E=Sfx:$2]

# Deepest directory finder: loop
RewriteCond %{DOCUMENT_ROOT}%{ENV:Pfx}/ -d
RewriteCond %{ENV:Sfx} ^(/[^/]*)(.*)$
RewriteRule . - [E=Pfx:%{ENV:Pfx}%1,E=Sfx:%2,S=-1]

Of course currently I have to use an N in place of that S=-1 and put in a check
for when to run the above at the top of the rewrite rules, which means that the
check gets evaluated on every request and every [N]

Csaba Gabor from Vienna
Comment 1 Bob Ionescu 2007-01-26 11:14:48 UTC
Created attachment 19468 [details]
proposed enhancement

patch against trunk
Comment 2 Bob Ionescu 2007-01-26 11:16:21 UTC
Please test the proposed patch. Be aware of bug 38642 (directory context:
continuously adding of path-info to already substituted paths) not to produce an
infinite loop when using negative arguments.
Comment 3 Bob Ionescu 2007-01-26 11:25:26 UTC
Created attachment 19469 [details]
proposed enhancement