Ampersand extends to the left part of regexes with RewriteRule,

Ampersand extends to the left part of regexes with RewriteRule,

am 04.12.2009 09:55:51 von Francis Galiegue

Hello everyone,

I've had the request to redirect a particular URI, say /foo or /foo/
to http://some.external.site/?var1=3Dval1&var2=3Dval2&var3=3Dva l3. The
Apache server version is 2.0.52 used on RHEL 4.x. I have tested with
2.2.3 on RHEL 5.x and the behaviour below is the same...

This looked quite simple, so I tried this:

----
RedirectMatch permanent ^/foo/?$
http://some.external.site/?var1=3Dval1&var2=3Dval2&var3=3Dva l3
----

This didn't quite work as expected since if I enter
http://first.site/foo/, what I see in the URL bar in the browser after
the redirect is:

http://some.external.site/?var1=3Dval1/foo/var2=3Dval2/foo/v ar3=3Dval3

So, the & has extended to the "left" part of the regex... Maybe this
bug was only with mod_alias's RedirectMatch, so I tried mod_rewrite
instead, in the following way:

----
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/foo/?$
RewriteRule ^/foo/?$
http://some.external.site/?var1=3Dval1&var2=3Dval2&var3=3Dva l3 [R,QSA]
----

Same thing! Out of despair, I even tried to combine mod_setenvif with
mod_rewrite:

----
SetEnvIf Request_URI ^ qs=3Dvar1=3Dval1&var2=3Dval2&var3=3Dval3
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/foo/?$
RewriteRule ^/foo/?$ http://some.external.site/?%{ENV:qs} [R,QSA]
----

But to my suprise, the ill-fated & striked again! The & in the
environment variable is replaced with whatever was matched by the
regex after Request_URI (even nothing, like in the above example) :(

Is this expected or is this a bug? I have tried and googled for hours
without being able to solve this problem... Is there a simple way to
just make the & literal in right parts? I have tried to backslash it
away to no effect...

Thanks in advance,
--=20

Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Ampersand extends to the left part of regexes with RewriteRule,

am 04.12.2009 13:54:25 von Francis Galiegue

On Fri, Dec 4, 2009 at 09:55, Francis GALIEGUE wrote:
> Hello everyone,
>
> I've had the request to redirect a particular URI, say /foo or /foo/
> to http://some.external.site/?var1=3Dval1&var2=3Dval2&var3=3Dva l3. The
> Apache server version is 2.0.52 used on RHEL 4.x. I have tested with
> 2.2.3 on RHEL 5.x and the behaviour below is the same...
>

This has also been tested on the latest Debian stable: the behavior is
exactly the same. It seems that it is the core Apache regex mechanism
which is in cause here.

Now, the question is, is it intended.

--=20

Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Ampersand extends to the left part of regexes with

am 04.12.2009 14:04:53 von Eric Covener

On 12/4/09, Francis GALIEGUE wrote:
> I have tried to backslash it

Backslash worked for me in the RedirectMatch test.

--
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Re: Ampersand extends to the left part of regexeswith RewriteRule, RedirectMatch and SetEnvIf:

am 04.12.2009 14:07:58 von aw

Francis GALIEGUE wrote:
> On Fri, Dec 4, 2009 at 09:55, Francis GALIEGUE wrote:
>> Hello everyone,
>>
>> I've had the request to redirect a particular URI, say /foo or /foo/
>> to http://some.external.site/?var1=val1&var2=val2&var3=val3. The
>> Apache server version is 2.0.52 used on RHEL 4.x. I have tested with
>> 2.2.3 on RHEL 5.x and the behaviour below is the same...
>>
>
> This has also been tested on the latest Debian stable: the behavior is
> exactly the same. It seems that it is the core Apache regex mechanism
> which is in cause here.
>
> Now, the question is, is it intended.
>
First, I believe that one mistake is to include the trailing question
mark into the URL which you redirect.
In http://my.server.com/foo/?var1=val1...
The "?" is not actually part of the URI. It is a separator between the
URI and the query string. So the URI to test is "/foo/", and not "/foo/?".
Second, in "RedirectMatch", "RewriteCond" and "RewriteRule", the
argument is a regexp, not a string. So when you write "/foo/?$", you
mean actually : "/foo", possibly followed by "/", followed by the end of
the string.
If you really wanted to test for a "?", you would have to escape it as "\?".

I do not know if this is the source of your particular problem, but it
may contribute to the strange results which you are seeing later.


------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Re: Ampersand extends to the left part of regexes

am 04.12.2009 14:18:09 von Francis Galiegue

On Fri, Dec 4, 2009 at 14:07, André Warnier wrote:
[...]
> First, I believe that one mistake is to include the trailing question mar=
k
> into the URL which you redirect.
> In http://my.server.com/foo/?var1=3Dval1...
> The "?" is not actually part of the URI. It is a separator between the UR=
I
> and the query string. So the URI to test is "/foo/", and not "/foo/?".
> Second, in "RedirectMatch", "RewriteCond" and "RewriteRule", the argument=
is
> a regexp, not a string. So when you write "/foo/?$", you mean actually :
> "/foo", possibly followed by "/", followed by the end of the string.
> If you really wanted to test for a "?", you would have to escape it as "\=
?".
>
> I do not know if this is the source of your particular problem, but it ma=
y
> contribute to the strange results which you are seeing later.
>

No, the ? is intended, I want to match either /foo or /foo/, so
^/foo/?$ is the correct regex, I'm sure about that.

The problem I have is with the & being systematically understood by
the right size of regexes to mean "the whole thing matched by the
matching left regex". While this is a common regex idiom in "basic"
regexes (sed acts this way for instance), it is not expected at all
from pcre (Perl doesn't know about &, and from what I've read about
pcre so far, pcre doesn't know about it either). Hence my puzzle.

--=20

Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Re: Ampersand extends to the left part of regexes

am 04.12.2009 14:37:17 von Eric Covener

On 12/4/09, Francis GALIEGUE wrote:

> The problem I have is with the & being systematically understood by
> the right size of regexes to mean "the whole thing matched by the
> matching left regex". While this is a common regex idiom in "basic"
> regexes (sed acts this way for instance), it is not expected at all
> from pcre (Perl doesn't know about &, and from what I've read about
> pcre so far, pcre doesn't know about it either). Hence my puzzle.

I think Apache is simulating perls $&, and I think it's on purpose.
Seems pretty unwise.

--
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Re: Ampersand extends to the left part of regexes

am 04.12.2009 14:39:38 von Eric Covener

On 12/4/09, Eric Covener wrote:
> On 12/4/09, Francis GALIEGUE wrote:
>
> > The problem I have is with the & being systematically understood by
> > the right size of regexes to mean "the whole thing matched by the
> > matching left regex". While this is a common regex idiom in "basic"
> > regexes (sed acts this way for instance), it is not expected at all
> > from pcre (Perl doesn't know about &, and from what I've read about
> > pcre so far, pcre doesn't know about it either). Hence my puzzle.
>
>
> I think Apache is simulating perls $&, and I think it's on purpose.
> Seems pretty unwise.

That is definitely the case.
--
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Ampersand extends to the left part of regexes with

am 04.12.2009 15:36:41 von Francis Galiegue

On Fri, Dec 4, 2009 at 14:04, Eric Covener wrote:
> On 12/4/09, Francis GALIEGUE wrote:
>> I have tried to backslash it
>
> Backslash worked for me in the RedirectMatch test.
>

Well, it does indeed... During my test period, I forgot that I had an
ExpiresDefault set to "access plus 1 month" in the test vhost...

So, yes, escaping the & with a backslash does work indeed, and I've
tested with the three configurations mentioned: the backslash works
each time.

--=20

Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Re: Ampersand extends to the left part of regexes

am 08.12.2009 14:20:42 von Francis Galiegue

On Fri, Dec 4, 2009 at 14:39, Eric Covener wrote:
[...]
>>
>> I think Apache is simulating perls $&, and I think it's on purpose.
>>  Seems pretty unwise.
>
> That is definitely the case.
>

If I file an issue on Apache's Bugzilla, will this be considered a bug?

--=20

Francis Galiegue
ONE2TEAM
Ingénieur système
Mob : +33 (0) 683 877 875
Tel : +33 (0) 178 945 552
fge@one2team.com
40 avenue Raymond Poincaré
75116 Paris

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Re: Ampersand extends to the left part of regexes

am 08.12.2009 14:25:08 von Eric Covener

On Tue, Dec 8, 2009 at 8:20 AM, Francis GALIEGUE wrote:
> On Fri, Dec 4, 2009 at 14:39, Eric Covener wrote:
> [...]
>>>
>>> I think Apache is simulating perls $&, and I think it's on purpose.
>>> =A0Seems pretty unwise.
>>
>> That is definitely the case.
>>
>
> If I file an issue on Apache's Bugzilla, will this be considered a bug?

I'm still a little lost here as to why this isn't more of a FAQ if it
impacts including an ampersand in any RewriteRule substitution, so I
may be wrong in the analysis.

It's minimally a documentation bug.

--=20
Eric Covener
covener@gmail.com

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Re: Ampersand extends to the left part of regexes with RewriteRule, RedirectMatch and SetEnvIf:

am 08.12.2009 16:43:12 von Rich Bowen

On Dec 8, 2009, at 08:20 , Francis GALIEGUE wrote:

> On Fri, Dec 4, 2009 at 14:39, Eric Covener wrote:
> [...]
>>>
>>> I think Apache is simulating perls $&, and I think it's on purpose.
>>> Seems pretty unwise.
>>
>> That is definitely the case.
>>
>
> If I file an issue on Apache's Bugzilla, will this be considered a
> bug?

Please do submit it, but perhaps as a documentation bug? I'll try to
remember to add a mention of this to the documentation, but a bugzilla
ticket will help us remember.

--
Rich Bowen
rbowen@rcbowen.com




------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org

Re: Re: Ampersand extends to the left part of regexeswith RewriteRule, RedirectMatch and SetEnvIf: i

am 08.12.2009 18:49:31 von Nick Kew

Rich Bowen wrote:

>> If I file an issue on Apache's Bugzilla, will this be considered a bug?
>
> Please do submit it, but perhaps as a documentation bug? I'll try to
> remember to add a mention of this to the documentation, but a bugzilla
> ticket will help us remember.

Is this really an Apache docs issue? It's down to the regexp library,
so surely the correct documentation for httpd is a reference to PCRE
(or Perl regexp) documentation?

Apache could put this in a tutorial/guide, but not really in
reference docs. Is that what you meant?

--
Nick Kew

------------------------------------------------------------ ---------
The official User-To-User support forum of the Apache HTTP Server Project.
See for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org