You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Francis GALIEGUE <fg...@one2team.com> on 2009/12/04 09:55:51 UTC

[users@httpd] Ampersand extends to the left part of regexes with RewriteRule, RedirectMatch and SetEnvIf: is that expected?

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 looked quite simple, so I tried this:

----
RedirectMatch permanent ^/foo/?$
http://some.external.site/?var1=val1&var2=val2&var3=val3
----

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=val1/foo/var2=val2/foo/var3=val3

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=val1&var2=val2&var3=val3 [R,QSA]
----

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

----
SetEnvIf Request_URI ^ qs=var1=val1&var2=val2&var3=val3
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,
-- 

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 <URL:http://httpd.apache.org/userslist.html> 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: [users@httpd] Ampersand extends to the left part of regexes with RewriteRule, RedirectMatch and SetEnvIf: is that expected?

Posted by Francis GALIEGUE <fg...@one2team.com>.
On Fri, Dec 4, 2009 at 14:04, Eric Covener <co...@gmail.com> wrote:
> On 12/4/09, Francis GALIEGUE <fg...@one2team.com> 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.

-- 

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 <URL:http://httpd.apache.org/userslist.html> 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: [users@httpd] Ampersand extends to the left part of regexes with RewriteRule, RedirectMatch and SetEnvIf: is that expected?

Posted by Eric Covener <co...@gmail.com>.
On 12/4/09, Francis GALIEGUE <fg...@one2team.com> 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 <URL:http://httpd.apache.org/userslist.html> 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: [users@httpd] Re: Ampersand extends to the left part of regexes with RewriteRule, RedirectMatch and SetEnvIf: is that expected?

Posted by Eric Covener <co...@gmail.com>.
On Tue, Dec 8, 2009 at 1:49 PM, Nick Kew <ni...@webthing.com> wrote:
> 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?

Searching for this old thread, missed your followup niq.  httpd was
stepping in the way and treating & as an alias for \0/$0 (entire
match):

http://svn.apache.org/viewvc?view=revision&revision=904765

There was some confusion ITT that Rewrite and mod_alias directives
were behaving the same way that I think was cleared up elsewhere.

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> 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: [users@httpd] Re: Ampersand extends to the left part of regexes with RewriteRule, RedirectMatch and SetEnvIf: is that expected?

Posted by Nick Kew <ni...@webthing.com>.
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 <URL:http://httpd.apache.org/userslist.html> 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: [users@httpd] Re: Ampersand extends to the left part of regexes with RewriteRule, RedirectMatch and SetEnvIf: is that expected?

Posted by Rich Bowen <rb...@rcbowen.com>.
On Dec 8, 2009, at 08:20 , Francis GALIEGUE wrote:

> On Fri, Dec 4, 2009 at 14:39, Eric Covener <co...@gmail.com> 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 <URL:http://httpd.apache.org/userslist.html> 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: [users@httpd] Re: Ampersand extends to the left part of regexes with RewriteRule, RedirectMatch and SetEnvIf: is that expected?

Posted by Eric Covener <co...@gmail.com>.
On Tue, Dec 8, 2009 at 8:20 AM, Francis GALIEGUE <fg...@one2team.com> wrote:
> On Fri, Dec 4, 2009 at 14:39, Eric Covener <co...@gmail.com> 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?

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.

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> 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: [users@httpd] Re: Ampersand extends to the left part of regexes with RewriteRule, RedirectMatch and SetEnvIf: is that expected?

Posted by Francis GALIEGUE <fg...@one2team.com>.
On Fri, Dec 4, 2009 at 14:39, Eric Covener <co...@gmail.com> 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?

-- 

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 <URL:http://httpd.apache.org/userslist.html> 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: [users@httpd] Re: Ampersand extends to the left part of regexes with RewriteRule, RedirectMatch and SetEnvIf: is that expected?

Posted by Eric Covener <co...@gmail.com>.
On 12/4/09, Eric Covener <co...@gmail.com> wrote:
> On 12/4/09, Francis GALIEGUE <fg...@one2team.com> 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 <URL:http://httpd.apache.org/userslist.html> 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: [users@httpd] Re: Ampersand extends to the left part of regexes with RewriteRule, RedirectMatch and SetEnvIf: is that expected?

Posted by Eric Covener <co...@gmail.com>.
On 12/4/09, Francis GALIEGUE <fg...@one2team.com> 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 <URL:http://httpd.apache.org/userslist.html> 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: [users@httpd] Re: Ampersand extends to the left part of regexes with RewriteRule, RedirectMatch and SetEnvIf: is that expected?

Posted by Francis GALIEGUE <fg...@one2team.com>.
On Fri, Dec 4, 2009 at 14:07, André Warnier <aw...@ice-sa.com> wrote:
[...]
> 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.
>

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.

-- 

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 <URL:http://httpd.apache.org/userslist.html> 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: [users@httpd] Re: Ampersand extends to the left part of regexes with RewriteRule, RedirectMatch and SetEnvIf: is that expected?

Posted by André Warnier <aw...@ice-sa.com>.
Francis GALIEGUE wrote:
> On Fri, Dec 4, 2009 at 09:55, Francis GALIEGUE <fg...@one2team.com> 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 <URL:http://httpd.apache.org/userslist.html> 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


[users@httpd] Re: Ampersand extends to the left part of regexes with RewriteRule, RedirectMatch and SetEnvIf: is that expected?

Posted by Francis GALIEGUE <fg...@one2team.com>.
On Fri, Dec 4, 2009 at 09:55, Francis GALIEGUE <fg...@one2team.com> 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.

-- 

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 <URL:http://httpd.apache.org/userslist.html> 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