Mailing List Archive

Unclear RewriteCond docs
https://httpd.apache.org/docs/current/rewrite/intro.html#rewritecond says

“Matches in the regular expressions contained in the RewriteConds can
be used as part of the Substitution in the RewriteRule using the
variables %1, %2, etc.“

This implies that more than one RewriteCond can be involved in
providing variables for the following rule.

However, unless I am missing something, only the last RewriteCond can
provide any variables.

It would be helpful if the docs could be more explicit on this.

Sebb

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: Unclear RewriteCond docs [ In reply to ]
Sebb,

Are you sure about that? I would verify before we venture to clarify the
docs.

On Mon, May 8, 2023 at 5:28?AM sebb <sebbaz@gmail.com> wrote:

> https://httpd.apache.org/docs/current/rewrite/intro.html#rewritecond says
>
> “Matches in the regular expressions contained in the RewriteConds can
> be used as part of the Substitution in the RewriteRule using the
> variables %1, %2, etc.“
>
> This implies that more than one RewriteCond can be involved in
> providing variables for the following rule.
>
> However, unless I am missing something, only the last RewriteCond can
> provide any variables.
>
> It would be helpful if the docs could be more explicit on this.
>
> Sebb
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>
Re: Unclear RewriteCond docs [ In reply to ]
On Mon, May 8, 2023 at 9:41?AM Frank Gingras <thumbs@apache.org> wrote:
>
> Sebb,
>
> Are you sure about that? I would verify before we venture to clarify the docs.

I think sebb is right, I've occasionally had to try to weirdly
propagate it or delay/combine it.

In a rule or condition, the captures of the preceding condition is available

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: Unclear RewriteCond docs [ In reply to ]
On 2023-05-08 08:44, Eric Covener wrote:
> On Mon, May 8, 2023 at 9:41?AM Frank Gingras <thumbs@apache.org> wrote:
>>
>> Sebb,
>>
>> Are you sure about that? I would verify before we venture to clarify the docs.
>
> I think sebb is right, I've occasionally had to try to weirdly
> propagate it or delay/combine it.
>
> In a rule or condition, the captures of the preceding condition is available

Only if the next condition is a regex condition. A literal string
comparison condition will not reset the previous captures. And yeah, you
can use the teststring value to add back your captures from the previous
condition:

# Get key value into %1
RewriteCond %{QUERY_STRING} "key=(.+)"
# Append query string with %1, get key value back into %1, bar value into %2
RewriteCond %1::%{QUERY_STRING} "^(.+)::.*bar=(.+)"
# Literal comparison, doesn't change backrefs:
RewriteCond %2 ="foo"
RewriteRule .* http://foo.bar/%1/%2


>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: Unclear RewriteCond docs [ In reply to ]
On Mon, May 8, 2023 at 10:29?AM Daniel Gruno <humbedooh@apache.org> wrote:
>
> On 2023-05-08 08:44, Eric Covener wrote:
> > On Mon, May 8, 2023 at 9:41?AM Frank Gingras <thumbs@apache.org> wrote:
> >>
> >> Sebb,
> >>
> >> Are you sure about that? I would verify before we venture to clarify the docs.
> >
> > I think sebb is right, I've occasionally had to try to weirdly
> > propagate it or delay/combine it.
> >
> > In a rule or condition, the captures of the preceding condition is available
>
> Only if the next condition is a regex condition. A literal string
> comparison condition will not reset the previous captures. And yeah, you
> can use the teststring value to add back your captures from the previous
> condition:
>
> # Get key value into %1
> RewriteCond %{QUERY_STRING} "key=(.+)"
> # Append query string with %1, get key value back into %1, bar value into %2
> RewriteCond %1::%{QUERY_STRING} "^(.+)::.*bar=(.+)"
> # Literal comparison, doesn't change backrefs:
> RewriteCond %2 ="foo"
> RewriteRule .* http://foo.bar/%1/%2

Ah, cool and tricky to document in an "intro". Maybe we can make sure
the gory details are right elsewhere, and caution that it's more
complicated with multiple conditions in the intro example.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: Unclear RewriteCond docs [ In reply to ]
On 2023-05-08 09:33, Eric Covener wrote:
> On Mon, May 8, 2023 at 10:29?AM Daniel Gruno <humbedooh@apache.org> wrote:
>>
>> On 2023-05-08 08:44, Eric Covener wrote:
>>> On Mon, May 8, 2023 at 9:41?AM Frank Gingras <thumbs@apache.org> wrote:
>>>>
>>>> Sebb,
>>>>
>>>> Are you sure about that? I would verify before we venture to clarify the docs.
>>>
>>> I think sebb is right, I've occasionally had to try to weirdly
>>> propagate it or delay/combine it.
>>>
>>> In a rule or condition, the captures of the preceding condition is available
>>
>> Only if the next condition is a regex condition. A literal string
>> comparison condition will not reset the previous captures. And yeah, you
>> can use the teststring value to add back your captures from the previous
>> condition:
>>
>> # Get key value into %1
>> RewriteCond %{QUERY_STRING} "key=(.+)"
>> # Append query string with %1, get key value back into %1, bar value into %2
>> RewriteCond %1::%{QUERY_STRING} "^(.+)::.*bar=(.+)"
>> # Literal comparison, doesn't change backrefs:
>> RewriteCond %2 ="foo"
>> RewriteRule .* http://foo.bar/%1/%2
>
> Ah, cool and tricky to document in an "intro". Maybe we can make sure
> the gory details are right elsewhere, and caution that it's more
> complicated with multiple conditions in the intro example.

Yeah, you can actually use this to accept and parse query string
key/value pairs given in an arbitrary order, but as you say, it gets
complex real fast - I am having to resort to making RewriteCond macros
to accomplish this without having to write 200 lines of config :)

We do have a page dedicated to advanced usage examples, maybe I can add
something to that page.

>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: Unclear RewriteCond docs [ In reply to ]
Another issue is that there is no link to the syntax to be used for
the various conditions.

For example, how does on express a file/path test or a string comparison?
AFAICT the only example is for a regex, though that is not made explicit.

Sebb

On Mon, 8 May 2023 at 15:38, Daniel Gruno <humbedooh@apache.org> wrote:
>
> On 2023-05-08 09:33, Eric Covener wrote:
> > On Mon, May 8, 2023 at 10:29?AM Daniel Gruno <humbedooh@apache.org> wrote:
> >>
> >> On 2023-05-08 08:44, Eric Covener wrote:
> >>> On Mon, May 8, 2023 at 9:41?AM Frank Gingras <thumbs@apache.org> wrote:
> >>>>
> >>>> Sebb,
> >>>>
> >>>> Are you sure about that? I would verify before we venture to clarify the docs.
> >>>
> >>> I think sebb is right, I've occasionally had to try to weirdly
> >>> propagate it or delay/combine it.
> >>>
> >>> In a rule or condition, the captures of the preceding condition is available
> >>
> >> Only if the next condition is a regex condition. A literal string
> >> comparison condition will not reset the previous captures. And yeah, you
> >> can use the teststring value to add back your captures from the previous
> >> condition:
> >>
> >> # Get key value into %1
> >> RewriteCond %{QUERY_STRING} "key=(.+)"
> >> # Append query string with %1, get key value back into %1, bar value into %2
> >> RewriteCond %1::%{QUERY_STRING} "^(.+)::.*bar=(.+)"
> >> # Literal comparison, doesn't change backrefs:
> >> RewriteCond %2 ="foo"
> >> RewriteRule .* http://foo.bar/%1/%2
> >
> > Ah, cool and tricky to document in an "intro". Maybe we can make sure
> > the gory details are right elsewhere, and caution that it's more
> > complicated with multiple conditions in the intro example.
>
> Yeah, you can actually use this to accept and parse query string
> key/value pairs given in an arbitrary order, but as you say, it gets
> complex real fast - I am having to resort to making RewriteCond macros
> to accomplish this without having to write 200 lines of config :)
>
> We do have a page dedicated to advanced usage examples, maybe I can add
> something to that page.
>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> > For additional commands, e-mail: users-help@httpd.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: Unclear RewriteCond docs [ In reply to ]
On Mon, May 8, 2023 at 1:22?PM sebb <sebbaz@gmail.com> wrote:
>
> Another issue is that there is no link to the syntax to be used for
> the various conditions.
>
> For example, how does on express a file/path test or a string comparison?
> AFAICT the only example is for a regex, though that is not made explicit.

Are you still in the intro document?

The comprehensive doc is
https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewritecond

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: Unclear RewriteCond docs [ In reply to ]
On Mon, 8 May 2023 at 19:00, Eric Covener <covener@gmail.com> wrote:
>
> On Mon, May 8, 2023 at 1:22?PM sebb <sebbaz@gmail.com> wrote:
> >
> > Another issue is that there is no link to the syntax to be used for
> > the various conditions.
> >
> > For example, how does on express a file/path test or a string comparison?
> > AFAICT the only example is for a regex, though that is not made explicit.
>
> Are you still in the intro document?

yes.

> The comprehensive doc is
> https://httpd.apache.org/docs/2.4/mod/mod_rewrite.html#rewritecond

Although there is a link to the full doc, it could be made more explicit.

Also the intro says "the second argument is a regular expression that
must match the variable". This is not the whole story. It would help
to be explicit in the text that there are 3 types of condition, at
which point a link to the full docs would be useful.

> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org