You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Bruno Tréguier <Br...@shom.fr> on 2012/03/21 10:02:09 UTC

[users@httpd] Problem when mixing RewriteRules and directives

Hello there,

I presently have a problem when trying to mix RewriteRules and 
<Location> directives. I searched the list archives but didn't find 
anything similar to my situation. Let's try to be synthetic. Here are 
the relevant config directives:

At "VirtualHost" level, among other things, here are the RewriteRules 
I'm using:

RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]

This set of RewriteRules are used with an online payment solution called 
"Magento". The idea, rather classical, is that the file "index.php" is a 
catch-all script, dealing with any URI which is not included in the 
exceptions above (typically, media files that are served "statically", 
or files really existing on the underlying filesystem).

So far, so good.

Now, what I want to do is add certain headers depending on the Request 
URI. Here is how I thought I could do it:

<Location /onlinestore/checkout>
   Header Add X-MyTraceHeader "CheckingOut"
</Location>

But it doesn't work, the header is never present in the server 
response... However, if I use the same method with a URI corresponding 
to a *real* file (e.g. a media file), so that the RewriteConds prevent 
the RewriteRule from being executed, it works perfectly !

So, it seems that the URI (held in the env. variable REQUEST_URI) is 
rewritten "in place" by the RewriteRule, meanwhile it's the one that is 
used by <Location> directive as well !

I tried another method, quite similar, via mod_setenvif:

SetenvIf REQUEST_URI "/onlinestore/checkout" CheckingOut=1
Header Add X-MyTraceHeader "CheckingOut" env=CheckingOut

But to no avail.

Any idea or pointer ?

Thanks in advance !

Best regards,

Bruno

-- 
- Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
-  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
-     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr

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


Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Bruno Tréguier <Br...@shom.fr>.
Le 23/03/2012 07:09, Bruno Tréguier a écrit :
> Le 23/03/2012 à 1:37, Igor Cicimov a écrit :
>> This is very interesting problem and I thought the issue was the typo
>> leaving your var empty. I'll have to do some research about the
>> mod_rewrite myself to confirm it precedes SetEnvIf in the order of
>> execution.
>>
>> Now I'm really curious about the solution my self and will try to find
>> some explanation even test this on one of my apaches if i find time to
>> do that.
>>
>> Have you tried this:
>>
>> Header add X-Debug-Request-URI "%{REQUEST_URI}i"
>
> Hi Igor,
>
> This leads to an error message at Apache restart time:
>
> Unrecognized header format %i
>
>
>> i think the difference is that the character "e" at the end means output
>> value and "i" means the input value of the REQUEST_URI.
>
> Doesn't seem to work, I'll check that out when I'm at work (answering
> from home at the moment).

I have just checked: unfortunately there doesn't seem to be a way to get 
the "input" value. The only modifier apart from "e" is "s", meaning that 
you want to get one of the SSL related variables.

No way to change the modules execution priority either. Looks like I'm 
doomed. :-/

Bruno

-- 
- Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
-  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
-     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr

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


Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Bruno Tréguier <Br...@shom.fr>.
Le 23/03/2012 à 1:37, Igor Cicimov a écrit :
> This is very interesting problem and I thought the issue was the typo
> leaving your var empty. I'll have to do some research about the
> mod_rewrite myself to confirm it precedes SetEnvIf in the order of
> execution.
>
> Now I'm really curious about the solution my self and will try to find
> some explanation even test this on one of my apaches if i find time to
> do that.
>
> Have you tried  this:
>
> Header add X-Debug-Request-URI "%{REQUEST_URI}i"

Hi Igor,

This leads to an error message at Apache restart time:

Unrecognized header format %i


> i think the difference is that the character "e" at the end means output
> value and "i" means the input value of the REQUEST_URI.

Doesn't seem to work, I'll check that out when I'm at work (answering 
from home at the moment).


> If that doesn't work try putting the 'Header add" statement before
> RewriteRules''

They already are, but as you point out, the order of execution may be in 
cause. :-(

Thanks a lot.

Regards,

Bruno

-- 
- Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
-  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
-     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr

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


[users@httpd] [SOLVED (well, kinda)] Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Bruno Tréguier <Br...@shom.fr>.
Hi everybody,

Following my previous posts regarding my RewriteRule/Location/SetEnvIf 
problem, a friend of mine suggested a neat solution, quite easy to apply.

The trick is to create, on the same machine, another vhost meant to 
serve exclusively as a reverse proxy, and which will add the intended 
header via the "LocationMatch" directive, working correctly in that case.

Here is my (stripped down) reverse proxy setting:

<VirtualHost 192.168.x.y:80>
         ServerName my.server.name

         <LocationMatch "/onlinestore/checkout.*">
           Header add X-CheckingOut "checking-out"
         </LocationMatch>

         ProxyPass               / http://my.server.name:8080/
         ProxyPassReverse        / http://my.server.name:8080/

</VirtualHost>

The initial vhost setting is then modified to listen on port 8080 
instead of 80. Very classical reverse proxy setting, of course, but 
quite useful to me, as this way the "Location" directives become useable 
for what I wanted them to do.

There is still a little mystery though, regarding the REQUEST_URI 
variable: if I try to print it in the headers via the following 
statement (in my new reverse proxy vhost of course):

         Header add X-Request-URI "%{REQUEST_URI}e"

The value is always "(null)".

However, if I do as follows:

         RewriteEngine on
         RewriteRule .* - [E=INFO_REQUEST_URI:%{REQUEST_URI}]
         Header add X-Request-URI "%{INFO_REQUEST_URI}e"

It works perfectly ! The trick here is to use the side-effect of a 
rewrite rule that does nothing at all, but set a new variable. That new 
variable (INFO_REQUEST_URI) then becomes useable in the "Header" 
statement, whereas the old one (REQUEST_URI) is not.

If anybody has an explanation for this, I'd be glad to read it, but this 
is in no way paramount.

Best regards to all.

Bruno

-- 
- Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
-  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
-     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr

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


Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Igor Cicimov <ic...@gmail.com>.
This is very interesting problem and I thought the issue was the typo
leaving your var empty. I'll have to do some research about the mod_rewrite
myself to confirm it precedes SetEnvIf in the order of execution.

Now I'm really curious about the solution my self and will try to find
some explanation even test this on one of my apaches if i find time to do
that.

Have you tried  this:

Header add X-Debug-Request-URI "%{REQUEST_URI}i"

i think the difference is that the character "e" at the end means output
value and "i" means the input value of the REQUEST_URI.

If that doesn't work try putting the 'Header add " statement before
RewriteRules''

Igor

On Fri, Mar 23, 2012 at 10:39 AM, Bruno Tréguier <Br...@shom.fr>wrote:

> Le 23/03/2012 à 0:23, Bruno Tréguier a écrit :
>
>  1) the X-Debug-Request-URI header is correct in the HTTP response,
>> example:
>>
>> X-Debug-Request-URI: /cartes-en-ligne/checkout/
>>
>> 2) the X-CheckingOut header, however, is NOT set. :-(
>>
>
> Sorry, that was another test. The right output is of course:
>
> X-Debug-Request-URI: /onlinestore/checkout/
>
>
> Bruno
>
>
> --
> - Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
> -  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
> -     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@httpd.**apache.org<us...@httpd.apache.org>
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Bruno Tréguier <Br...@shom.fr>.
Le 23/03/2012 à 0:23, Bruno Tréguier a écrit :
> 1) the X-Debug-Request-URI header is correct in the HTTP response, example:
>
> X-Debug-Request-URI: /cartes-en-ligne/checkout/
>
> 2) the X-CheckingOut header, however, is NOT set. :-(

Sorry, that was another test. The right output is of course:

X-Debug-Request-URI: /onlinestore/checkout/

Bruno


-- 
- Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
-  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
-     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr

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


Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Bruno Tréguier <Br...@shom.fr>.
Le 22/03/2012 à 22:50, Igor Cicimov a écrit :
> "The problem I'm facing here seems to rely in the fact that the
> variables I'm trying to use (like "THE_REQUEST", for example) are only
> defined within mod_rewrite's scope, and are not available to other
> directives like SetenvIf."
>
> And i dont think this is correct i have used SetEnvIf with REQUEST_URI
> before.

You're certainly right. REQUEST_URI is a standard variable, which can be 
used in CGIs and the rest, from what the documentation says.

This makes my problem even stranger...

Following your advice, I checked whether I still had a Location 
statement somewhere, but no, I had removed after our first exchange, 
when you showed me that solution wasn't useable.

Then I tried to stick with the SetEnvIf method. Though I don't think 
statements are case-sensitive, I wrote it exactly that way, but still no 
luck.

Sounds rather simple:

  Header add X-Debug-Request-URI "%{REQUEST_URI}e"

  SetEnvIf REQUEST_URI "/onlinestore/checkout.*" CheckingOut=1
  Header add X-CheckingOut "checking-out" env=CheckingOut


Behaviour:
1) the X-Debug-Request-URI header is correct in the HTTP response, example:

X-Debug-Request-URI: /cartes-en-ligne/checkout/

2) the X-CheckingOut header, however, is NOT set. :-(

All seems to go as if the REQUEST_URI seen by the SetEnvIf statement had 
already been modified by the RewriteRules. I haven't found any way to 
save it in another env. variable (let's say SAVED_REQUEST_URI) before it 
gets used...

This is driving me crazy. Thanks anyway for all your suggestions.

Best regards,

Bruno

-- 
- Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
-  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
-     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr

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


Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Igor Cicimov <ic...@gmail.com>.
Hold on, it should be SetEnvIf and not SetenvIf in your stanza!
 On Mar 23, 2012 8:50 AM, "Igor Cicimov" <ic...@gmail.com> wrote:

> "The problem I'm facing here seems to rely in the fact that the variables
> I'm trying to use (like "THE_REQUEST", for example) are only defined within
> mod_rewrite's scope, and are not available to other directives like
> SetenvIf."
>
> And i dont think this is correct i have used SetEnvIf with REQUEST_URI
> before.
> On Mar 23, 2012 8:47 AM, "Igor Cicimov" <ic...@gmail.com> wrote:
>
>> Do you have SetEnvIf and Location togather in the config? Remove the
>> Location one and leave the SetEnvIf only to catch the env var for the
>> header. I read somewhere a case when LocationMatch was affecting SetEnvIf.
>>  On Mar 23, 2012 1:26 AM, "Bruno Tréguier" <Br...@shom.fr>
>> wrote:
>>
>>> Le 22/03/2012 11:11, Igor Cicimov a écrit :
>>>
>>>> Why don't you just do it this way:
>>>>
>>>> RewriteCond %{REQUEST_URI} !^/(media|skin|js)/ [OR]
>>>> RewriteCond %{REQUEST_URI} !^/onlinestore/checkout
>>>> RewriteCond %{REQUEST_FILENAME} !-f
>>>> RewriteCond %{REQUEST_FILENAME} !-d
>>>> RewriteCond %{REQUEST_FILENAME} !-l
>>>> RewriteRule .* index.php [L]
>>>>
>>>> and solve your rewrite problem?
>>>>
>>>
>>> Because the path /onlinestore/checkout is not an exception to the rule,
>>> and also has to be dealt with by the "index.php" catch-all script.
>>>
>>> I just want to conditionally set a header in the HTTP response, based on
>>> the original URI, before it is fiddled with by rewriting process.
>>>
>>> The problem I'm facing here seems to rely in the fact that the variables
>>> I'm trying to use (like "THE_REQUEST", for example) are only defined within
>>> mod_rewrite's scope, and are not available to other directives like
>>> SetenvIf.
>>>
>>> Regards,
>>>
>>> Bruno
>>>
>>> --
>>> - Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
>>> -  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
>>> -     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr
>>>
>>> ------------------------------**------------------------------**
>>> ---------
>>> To unsubscribe, e-mail: users-unsubscribe@httpd.**apache.org<us...@httpd.apache.org>
>>> For additional commands, e-mail: users-help@httpd.apache.org
>>>
>>>

Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Igor Cicimov <ic...@gmail.com>.
"The problem I'm facing here seems to rely in the fact that the variables
I'm trying to use (like "THE_REQUEST", for example) are only defined within
mod_rewrite's scope, and are not available to other directives like
SetenvIf."

And i dont think this is correct i have used SetEnvIf with REQUEST_URI
before.
On Mar 23, 2012 8:47 AM, "Igor Cicimov" <ic...@gmail.com> wrote:

> Do you have SetEnvIf and Location togather in the config? Remove the
> Location one and leave the SetEnvIf only to catch the env var for the
> header. I read somewhere a case when LocationMatch was affecting SetEnvIf.
>  On Mar 23, 2012 1:26 AM, "Bruno Tréguier" <Br...@shom.fr> wrote:
>
>> Le 22/03/2012 11:11, Igor Cicimov a écrit :
>>
>>> Why don't you just do it this way:
>>>
>>> RewriteCond %{REQUEST_URI} !^/(media|skin|js)/ [OR]
>>> RewriteCond %{REQUEST_URI} !^/onlinestore/checkout
>>> RewriteCond %{REQUEST_FILENAME} !-f
>>> RewriteCond %{REQUEST_FILENAME} !-d
>>> RewriteCond %{REQUEST_FILENAME} !-l
>>> RewriteRule .* index.php [L]
>>>
>>> and solve your rewrite problem?
>>>
>>
>> Because the path /onlinestore/checkout is not an exception to the rule,
>> and also has to be dealt with by the "index.php" catch-all script.
>>
>> I just want to conditionally set a header in the HTTP response, based on
>> the original URI, before it is fiddled with by rewriting process.
>>
>> The problem I'm facing here seems to rely in the fact that the variables
>> I'm trying to use (like "THE_REQUEST", for example) are only defined within
>> mod_rewrite's scope, and are not available to other directives like
>> SetenvIf.
>>
>> Regards,
>>
>> Bruno
>>
>> --
>> - Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
>> -  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
>> -     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@httpd.**apache.org<us...@httpd.apache.org>
>> For additional commands, e-mail: users-help@httpd.apache.org
>>
>>

Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Igor Cicimov <ic...@gmail.com>.
Do you have SetEnvIf and Location togather in the config? Remove the
Location one and leave the SetEnvIf only to catch the env var for the
header. I read somewhere a case when LocationMatch was affecting SetEnvIf.
 On Mar 23, 2012 1:26 AM, "Bruno Tréguier" <Br...@shom.fr> wrote:

> Le 22/03/2012 11:11, Igor Cicimov a écrit :
>
>> Why don't you just do it this way:
>>
>> RewriteCond %{REQUEST_URI} !^/(media|skin|js)/ [OR]
>> RewriteCond %{REQUEST_URI} !^/onlinestore/checkout
>> RewriteCond %{REQUEST_FILENAME} !-f
>> RewriteCond %{REQUEST_FILENAME} !-d
>> RewriteCond %{REQUEST_FILENAME} !-l
>> RewriteRule .* index.php [L]
>>
>> and solve your rewrite problem?
>>
>
> Because the path /onlinestore/checkout is not an exception to the rule,
> and also has to be dealt with by the "index.php" catch-all script.
>
> I just want to conditionally set a header in the HTTP response, based on
> the original URI, before it is fiddled with by rewriting process.
>
> The problem I'm facing here seems to rely in the fact that the variables
> I'm trying to use (like "THE_REQUEST", for example) are only defined within
> mod_rewrite's scope, and are not available to other directives like
> SetenvIf.
>
> Regards,
>
> Bruno
>
> --
> - Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
> -  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
> -     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@httpd.**apache.org<us...@httpd.apache.org>
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Bruno Tréguier <Br...@shom.fr>.
Le 22/03/2012 11:11, Igor Cicimov a écrit :
> Why don't you just do it this way:
>
> RewriteCond %{REQUEST_URI} !^/(media|skin|js)/ [OR]
> RewriteCond %{REQUEST_URI} !^/onlinestore/checkout
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteCond %{REQUEST_FILENAME} !-l
> RewriteRule .* index.php [L]
>
> and solve your rewrite problem?

Because the path /onlinestore/checkout is not an exception to the rule, 
and also has to be dealt with by the "index.php" catch-all script.

I just want to conditionally set a header in the HTTP response, based on 
the original URI, before it is fiddled with by rewriting process.

The problem I'm facing here seems to rely in the fact that the variables 
I'm trying to use (like "THE_REQUEST", for example) are only defined 
within mod_rewrite's scope, and are not available to other directives 
like SetenvIf.

Regards,

Bruno

-- 
- Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
-  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
-     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr

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


Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Igor Cicimov <ic...@gmail.com>.
Why don't you just do it this way:

RewriteCond %{REQUEST_URI} !^/(media|skin|js)/ [OR]
RewriteCond %{REQUEST_URI} !^/onlinestore/checkout
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]

and solve your rewrite problem?


On Thu, Mar 22, 2012 at 5:22 AM, Bruno Tréguier <Br...@shom.fr>wrote:

> Le 21/03/2012 à 12:57, Igor Cicimov a écrit :
>
>  Lets see ... why is mod_rewrite called mod rewrite? Probably because it
>> rewrites something and that something is the url.
>>
>
> Well, as strange as it might seem to you, I had figured that out myself,
> you see. ;-)
>
>
>
>  So you need to catch
>> what ever you need before it gets rewritten by mod_rewrite. And in your
>> case the Location comes too late ...
>>
>
> Ok for the Location statement behaviour. But what about the REQUEST_URI
> variable ? Why is it modified by the rewriting process (or so it seems) ?
>
> If it weren't the case, at least the "SetenvIf" scheme should work, but it
> doesn't... So I tried to debug that, by using a header that I called
> "X-Debug".
>
> Here is the conditional setting of the "X-MyTraceHeader" header:
>
> SetenvIf REQUEST_URI "/onlinestore/checkout.*" CheckingOut=1
>
> Header Add X-MyTraceHeader "CheckingOut" env=CheckingOut
>
> And here is the X-Debug header:
>
> Header add X-Debug "REQUEST_URI=%{REQUEST_URI}e
> CheckingOut=%{CheckingOut}e"
>
> The output is really strange:
>
> X-Debug: REQUEST_URI=/onlinestore/**checkout/cart/updatePost/
> CheckingOut=(null)
>
> So, the X-Debug header shows that the REQUEST_URI variable is correctly
> set, its value *should* have triggered the SetenvIf condition and
> subsequently set the "CheckingOut" variable, which obviously is not the
> case. I also checked by eliminating the regular expression on the SetenvIf
> line, putting the whole path, but the behaviour is the same.
>
> This is really puzzling me. Any explanation, anyone ?
>
>
> Regards,
>
> Bruno
>
> --
> - Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
> -  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
> -     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@httpd.**apache.org<us...@httpd.apache.org>
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Bruno Tréguier <Br...@shom.fr>.
Le 21/03/2012 à 12:57, Igor Cicimov a écrit :
> Lets see ... why is mod_rewrite called mod rewrite? Probably because it
> rewrites something and that something is the url.

Well, as strange as it might seem to you, I had figured that out myself, 
you see. ;-)


> So you need to catch
> what ever you need before it gets rewritten by mod_rewrite. And in your
> case the Location comes too late ...

Ok for the Location statement behaviour. But what about the REQUEST_URI 
variable ? Why is it modified by the rewriting process (or so it seems) ?

If it weren't the case, at least the "SetenvIf" scheme should work, but 
it doesn't... So I tried to debug that, by using a header that I called 
"X-Debug".

Here is the conditional setting of the "X-MyTraceHeader" header:

SetenvIf REQUEST_URI "/onlinestore/checkout.*" CheckingOut=1
Header Add X-MyTraceHeader "CheckingOut" env=CheckingOut

And here is the X-Debug header:

Header add X-Debug "REQUEST_URI=%{REQUEST_URI}e CheckingOut=%{CheckingOut}e"

The output is really strange:

X-Debug: REQUEST_URI=/onlinestore/checkout/cart/updatePost/ 
CheckingOut=(null)

So, the X-Debug header shows that the REQUEST_URI variable is correctly 
set, its value *should* have triggered the SetenvIf condition and 
subsequently set the "CheckingOut" variable, which obviously is not the 
case. I also checked by eliminating the regular expression on the 
SetenvIf line, putting the whole path, but the behaviour is the same.

This is really puzzling me. Any explanation, anyone ?

Regards,

Bruno

-- 
- Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
-  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
-     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr

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


Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Igor Cicimov <ic...@gmail.com>.
Lets see ... why is mod_rewrite called mod rewrite? Probably because it
rewrites something and that something is the url. So you need to catch what
ever you need before it gets rewritten by mod_rewrite. And in your case the
Location comes too late ...
 On Mar 21, 2012 8:55 PM, "Bruno Tréguier" <Br...@shom.fr> wrote:

> Le 21/03/2012 10:15, Igor Cicimov a écrit :
>
>> Ummmm if you read your post you will find that you have answered your
>> own question. The /onlinestore/checkout matches your rewrite rule thus
>> gets redirected to index.php before the Location statement gets into
>> action. I think you need to read the apache documentation about the
>> order in which the rules and statements get executed.
>>
>
> Hi Igor,
>
> I realised that the Location statement was impacted by RewriteRules, but
> what puzzles me is that the environment variable REQUEST_URI is also
> impacted. The client requested a given URI, whatever is done then via
> RewriteRules, it seemed to me that there should be a way to save that
> information somewhere, and REQUEST_URI appeared to me as the perfect place
> for that.
>
> That way, even if the <Location> method didn't work, the SetenvIf method
> would.
>
> Thanks anyway for that answer.
>
> Regards,
>
> Bruno
>
> --
> - Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
> -  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
> -     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@httpd.**apache.org<us...@httpd.apache.org>
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Bruno Tréguier <Br...@shom.fr>.
Le 21/03/2012 10:15, Igor Cicimov a écrit :
> Ummmm if you read your post you will find that you have answered your
> own question. The /onlinestore/checkout matches your rewrite rule thus
> gets redirected to index.php before the Location statement gets into
> action. I think you need to read the apache documentation about the
> order in which the rules and statements get executed.

Hi Igor,

I realised that the Location statement was impacted by RewriteRules, but 
what puzzles me is that the environment variable REQUEST_URI is also 
impacted. The client requested a given URI, whatever is done then via 
RewriteRules, it seemed to me that there should be a way to save that 
information somewhere, and REQUEST_URI appeared to me as the perfect 
place for that.

That way, even if the <Location> method didn't work, the SetenvIf method 
would.

Thanks anyway for that answer.

Regards,

Bruno

-- 
- Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
-  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
-     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr

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


Re: [users@httpd] Problem when mixing RewriteRules and directives

Posted by Igor Cicimov <ic...@gmail.com>.
Ummmm if you read your post you will find that you have answered your own
question. The /onlinestore/checkout matches your rewrite rule thus gets
redirected to index.php before the Location statement gets into action. I
think you need to read the apache documentation about the order in which
the rules and statements get executed.
On Mar 21, 2012 8:02 PM, "Bruno Tréguier" <Br...@shom.fr> wrote:

> Hello there,
>
> I presently have a problem when trying to mix RewriteRules and <Location>
> directives. I searched the list archives but didn't find anything similar
> to my situation. Let's try to be synthetic. Here are the relevant config
> directives:
>
> At "VirtualHost" level, among other things, here are the RewriteRules I'm
> using:
>
> RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
> RewriteCond %{REQUEST_FILENAME} !-f
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteCond %{REQUEST_FILENAME} !-l
> RewriteRule .* index.php [L]
>
> This set of RewriteRules are used with an online payment solution called
> "Magento". The idea, rather classical, is that the file "index.php" is a
> catch-all script, dealing with any URI which is not included in the
> exceptions above (typically, media files that are served "statically", or
> files really existing on the underlying filesystem).
>
> So far, so good.
>
> Now, what I want to do is add certain headers depending on the Request
> URI. Here is how I thought I could do it:
>
> <Location /onlinestore/checkout>
>  Header Add X-MyTraceHeader "CheckingOut"
> </Location>
>
> But it doesn't work, the header is never present in the server response...
> However, if I use the same method with a URI corresponding to a *real* file
> (e.g. a media file), so that the RewriteConds prevent the RewriteRule from
> being executed, it works perfectly !
>
> So, it seems that the URI (held in the env. variable REQUEST_URI) is
> rewritten "in place" by the RewriteRule, meanwhile it's the one that is
> used by <Location> directive as well !
>
> I tried another method, quite similar, via mod_setenvif:
>
> SetenvIf REQUEST_URI "/onlinestore/checkout" CheckingOut=1
> Header Add X-MyTraceHeader "CheckingOut" env=CheckingOut
>
> But to no avail.
>
> Any idea or pointer ?
>
> Thanks in advance !
>
> Best regards,
>
> Bruno
>
> --
> - Service Hydrographique et Oceanographique de la Marine  -  DMGS/INF
> -  13, rue du Chatellier -  CS 92803  - 29228 Brest Cedex 2, FRANCE
> -     Phone: +33 2 98 22 17 49  -  Email: Bruno.Treguier@shom.fr
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@httpd.**apache.org<us...@httpd.apache.org>
> For additional commands, e-mail: users-help@httpd.apache.org
>
>