Bug 53080 - Apache mod_rewrite Introduction - RewriteRule Basics: misleading about what Pattern is matched against
Summary: Apache mod_rewrite Introduction - RewriteRule Basics: misleading about what P...
Status: RESOLVED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: Documentation (show other bugs)
Version: 2.5-HEAD
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: HTTP Server Documentation List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-04-13 17:06 UTC by Philippe Cloutier
Modified: 2012-05-05 15:20 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Philippe Cloutier 2012-04-13 17:06:12 UTC
http://httpd.apache.org/docs/trunk/en/rewrite/intro.html#rewriterule contains:

The Pattern is always a regular expression matched against the URL-Path of the incoming request (the part after the hostname but before any question mark indicating the beginning of a query string) or, in per-directory context, against the request's path relative to the directory for which the rule is defined.

This is correct for the first RewriteRule, but not necessarily for the following rules. As explained in http://httpd.apache.org/docs/trunk/en/mod/mod_rewrite.html#rewriterule :
On the first RewriteRule, it is matched against the (%-decoded) URL-path (or file-path, depending on the context) of the request. Subsequent patterns are matched against the output of the last matching RewriteRule.

I suggest this formulation instead:

Pattern is a regular expression. It is initially (for the first rewrite rule) matched against the URL-path of the incoming request (the part after the hostname but before any question mark indicating the beginning of a query string) or, in per-directory context, against the request's path relative to the directory for which the rule is defined.

This doesn't specify what happens after the first rewrite rule, so it's incomplete, but it's just an introduction, so I think it's fine as long as it's not misleading.
Comment 1 Daniel Gruno 2012-05-01 09:45:56 UTC
I have applied your suggestion and added a note that the URL-path of the incoming request is matched in the first rewriterule or until a substitution takes place, and that rules that follow are matched against the substituted value instead.

Do give it a read-through and tell me what you think of this new wording.
Comment 2 Philippe Cloutier 2012-05-03 18:56:30 UTC
Thank you Daniel. The paragraph now contains:

for the first rewrite rule or until a substitution occurs

It would be slightly clearer to have:

for the first rewrite rule and until a substitution occurs

Also, in "Once a substitution has occured, the rules that follow are matched against the substituted value.", "the substituted value" is confusing since there can be several. Replacing "substituted value" with "last substitution" would clarify.
Comment 3 Kyle Hamilton 2012-05-03 21:02:17 UTC
So, basically, what I'm reading is that RewriteRule is most like Perl's $_ scalar.

"Once a substitution has occured, the rules that follow are matched against the substituted value."

I propose:

Once a substitution has occurred in the value, the rules that follow are matched against the value as it exists after the substitution has taken place.
Comment 4 Eric Covener 2012-05-03 21:05:48 UTC
(In reply to comment #3)
> So, basically, what I'm reading is that RewriteRule is most like Perl's $_
> scalar.
> 
> "Once a substitution has occured, the rules that follow are matched against
> the substituted value."
> 
> I propose:
> 
> Once a substitution has occurred in the value, the rules that follow are
> matched against the value as it exists after the substitution has taken
> place.

I think this is a step backwards
Comment 5 Kyle Hamilton 2012-05-04 00:18:01 UTC
(In reply to comment #4)
> (In reply to comment #3)
> > So, basically, what I'm reading is that RewriteRule is most like Perl's $_
> > scalar.
> > 
> > "Once a substitution has occured, the rules that follow are matched against
> > the substituted value."
> > 
> > I propose:
> > 
> > Once a substitution has occurred in the value, the rules that follow are
> > matched against the value as it exists after the substitution has taken
> > place.
> 
> I think this is a step backwards

Why?

How about:

All mod_rewrite rules match against and destructively transform a single value.  The value after a given transformation is the value seen and matched against by the next rule in the chain.
Comment 6 Philippe Cloutier 2012-05-04 02:29:37 UTC
Hi Kyle,
I can't speak for Eric, but I find this part unclear:

the value as it exists after the substitution has taken place

A reader may wonder "The value of what?".

As for your second suggestion, I'm not sure what you're proposing exactly (how that sentence would integrate in the rest of the section), but I have no idea of what "destructively transform" would mean.
Comment 7 Rich Bowen 2012-05-04 11:19:42 UTC
Are we trying to say something like

Each rule encountered modifies the value of the required uri as you go along. So each rule gets the modified value from any previous rule.

It appears that as we try to get more technically accurate we become less clear. doesn't feel like progress to me.
Comment 8 Kyle Hamilton 2012-05-04 20:10:33 UTC
(In reply to comment #7)
> Are we trying to say something like
> 
> Each rule encountered modifies the value of the required uri as you go
> along. So each rule gets the modified value from any previous rule.
> 
> It appears that as we try to get more technically accurate we become less
> clear. doesn't feel like progress to me.

In each rule, there is a pattern, a substitution, and optionally a set of flags.

The first rule's input is the URI requested by the client.  For each rule, when the pattern does not match, that rule's output is its unaltered input.  When it matches, the substitution/flags are applied and the substituted string is the rule's output.  The output of the prior rule is the input to the next.  When the rule is the final rule in the chain, its output is the final rewritten URI or URL that httpd processes.  There are flags which can tell httpd not to process any rules following the flagged rule.
Comment 9 Rich Bowen 2012-05-04 20:20:45 UTC
Guys, this ticket is marked as closed. If it's closed, please move on. If it's not fixed yet, please either reopen it, or, preferably, open a new one with a clearer statement of what problem it is that we're trying to solve. It is no longer at all clear what problem we're chasing.

Thanks.
Comment 10 Philippe Cloutier 2012-05-05 15:20:12 UTC
Regarding "The output of the prior rule is the input to the next.", there may be several prior rules. And the "output" of any prior rule does not necessarily exist, if no prior rule ran.