Bug 41412 - RewriteRule Skip should take negative arguments
Summary: RewriteRule Skip should take negative arguments
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_rewrite (show other bugs)
Version: 2.5-HEAD
Hardware: Other All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
Keywords: PatchAvailable
Depends on:
Reported: 2007-01-19 06:11 UTC by Csaba Gabor
Modified: 2007-01-26 11:25 UTC (History)
0 users

proposed enhancement (550 bytes, patch)
2007-01-26 11:14 UTC, Bob Ionescu
Details | Diff
proposed enhancement (863 bytes, patch)
2007-01-26 11:25 UTC, Bob Ionescu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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