You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Cordente Emmanuel <EC...@VOYAGES-SNCF.COM> on 2017/09/06 11:54:07 UTC

[users@httpd] Request_URI and ErrorDocument interaction ?

Hi,

I'm having a problem using together Request_URI and ErrorDocument, and I can't solved it by myself.
My initial need was to very simple: separate the request path in the logformat.

I've started to use the %U format string, it was fine, but I notice that in case of some rewriterule my logfile was containg the result of the rewrite and not the original request path.
So I've figured to make it work doing this:

SetEnvIf Request_URI ^(.*)$ originalPath=$1
LogFormat "... , {originalPath}e , ..."

This work in most of the case, but I still have a problem with error pages.
In my configuration I use an ErrorDocument directive:

ErrorDocument 404 /pagenotfound

When I call an unknown url (404) like: /nothing , the generated log is /pagenotfound (it should be /nothing)
This is very problematic, because I cannot analyse the origin of 404 errors.

Why the Request_URI environment variable is change by the ErrorDocument treatment ?

Is there a way to get the real request path, either with rewriterule and ErrorDocument ?

Thank you.

Emmanuel


RE: [users@httpd] Request_URI and ErrorDocument interaction ?

Posted by Cordente Emmanuel <EC...@VOYAGES-SNCF.COM>.
Yes. Thank again.

Emmanuel


-----Original Message-----
From: Yann Ylavic [mailto:ylavic.dev@gmail.com] 
Sent: lundi 18 septembre 2017 12:06
To: users@httpd.apache.org
Subject: Re: [users@httpd] Request_URI and ErrorDocument interaction ?

On Mon, Sep 18, 2017 at 11:48 AM, Cordente Emmanuel <EC...@voyages-sncf.com> wrote:
>
> Is there any documentation explaining the all the env variable of the previous request are stored under REDIRECT_xxx ?

https://httpd.apache.org/docs/2.4/custom-error.html#variables seems to mention that.

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


Re: [users@httpd] Request_URI and ErrorDocument interaction ?

Posted by Yann Ylavic <yl...@gmail.com>.
On Mon, Sep 18, 2017 at 11:48 AM, Cordente Emmanuel
<EC...@voyages-sncf.com> wrote:
>
> Is there any documentation explaining the all the env variable of the previous request are stored under REDIRECT_xxx ?

https://httpd.apache.org/docs/2.4/custom-error.html#variables seems to
mention that.

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


RE: [users@httpd] Request_URI and ErrorDocument interaction ?

Posted by Cordente Emmanuel <EC...@VOYAGES-SNCF.COM>.
That's working !
Thanks a lot, this make my day :-)

Is there any documentation explaining the all the env variable of the previous request are stored under REDIRECT_xxx ?

Emmanuel


-----Original Message-----
From: Yann Ylavic [mailto:ylavic.dev@gmail.com] 
Sent: lundi 18 septembre 2017 10:10
To: users@httpd.apache.org
Subject: Re: [users@httpd] Request_URI and ErrorDocument interaction ?

On Mon, Sep 18, 2017 at 10:06 AM, Yann Ylavic <yl...@gmail.com> wrote:
> Typo below.
>
> On Mon, Sep 18, 2017 at 9:50 AM, Yann Ylavic <yl...@gmail.com> wrote:
>>
>> RewriteCond %{ENV:originalPath} ^$
>
> The above should be:
> RewriteCond %{ENV:REDIRECT_originalPath} ^$
>
>> RewriteRule ^ - [E=originalPath:%{REQUEST_URI}]
>>
>> RewriteCond %{ENV:REDIRECT_originalPath} ^(.+)$ RewriteRule ^ - 
>> [E=originalPath:%1]

Argh, no, the order is not correct, please try:

RewriteCond %{ENV:REDIRECT_originalPath} ^(.+)$ RewriteRule ^ - [E=originalPath:%1]

RewriteCond %{ENV:originalPath} ^$
RewriteRule ^ - [E=originalPath:%{REQUEST_URI}]

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


Re: [users@httpd] Request_URI and ErrorDocument interaction ?

Posted by Yann Ylavic <yl...@gmail.com>.
On Mon, Sep 18, 2017 at 10:06 AM, Yann Ylavic <yl...@gmail.com> wrote:
> Typo below.
>
> On Mon, Sep 18, 2017 at 9:50 AM, Yann Ylavic <yl...@gmail.com> wrote:
>>
>> RewriteCond %{ENV:originalPath} ^$
>
> The above should be:
> RewriteCond %{ENV:REDIRECT_originalPath} ^$
>
>> RewriteRule ^ - [E=originalPath:%{REQUEST_URI}]
>>
>> RewriteCond %{ENV:REDIRECT_originalPath} ^(.+)$
>> RewriteRule ^ - [E=originalPath:%1]

Argh, no, the order is not correct, please try:

RewriteCond %{ENV:REDIRECT_originalPath} ^(.+)$
RewriteRule ^ - [E=originalPath:%1]

RewriteCond %{ENV:originalPath} ^$
RewriteRule ^ - [E=originalPath:%{REQUEST_URI}]

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


Re: [users@httpd] Request_URI and ErrorDocument interaction ?

Posted by Yann Ylavic <yl...@gmail.com>.
Typo below.

On Mon, Sep 18, 2017 at 9:50 AM, Yann Ylavic <yl...@gmail.com> wrote:
>
> RewriteCond %{ENV:originalPath} ^$

The above should be:
RewriteCond %{ENV:REDIRECT_originalPath} ^$

> RewriteRule ^ - [E=originalPath:%{REQUEST_URI}]
>
> RewriteCond %{ENV:REDIRECT_originalPath} ^(.+)$
> RewriteRule ^ - [E=originalPath:%1]

>
>
> Regards,
> Yann.

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


Re: [users@httpd] Request_URI and ErrorDocument interaction ?

Posted by Yann Ylavic <yl...@gmail.com>.
Sorry for the delay, I missed your response.

On Mon, Sep 11, 2017 at 1:56 PM, Cordente Emmanuel
<EC...@voyages-sncf.com> wrote:
> Thank you for the proposition, I tried  it without success.
>
> I've used:
> RewriteCond %{ENV:REDIRECT_URL} ^(.+)$
> RewriteRule ^ - [E=originalPath:%1]
>
> RewriteCond %{ENV:originalPath} ^$
> RewriteRule ^ - [E=originalPath:%{REQUEST_URI}]
>
> ErrorDocument 404 /pagenotfound
>
> In the rewrite log I see something strange:
>  [11/Sep/2017:13:27:18 +0200] [myvhost/sid#1df93xx][rid# 7f98e8154870/initial] (5) setting env variable 'originalPath' to '/nothing'
>  [11/Sep/2017:13:27:18 +0200] [myvhost/sid#1df93xx][rid# 7f98e80aced8/initial/redir#1] (5) setting env variable 'originalPath' to '/pagenotfound'
>
> The 1st line is what we wanted, but I don't understand the second line.
> It's like the internal redirect of the ErrorDocument run again the rewrite rule like if it is a brand new request in another context (without the env variable defined before)

Yes, the internal redirect "restarts" the request processing, hence
rewrite rules too.
I missed that REDIRECT_URL was defined in CGI context only, the
general scheme for redirects is that env variables from the previous
request are prefixed with "REDIRECT_".

>
> Any idea ?

Given that, maybe the below?

RewriteCond %{ENV:originalPath} ^$
RewriteRule ^ - [E=originalPath:%{REQUEST_URI}]

RewriteCond %{ENV:REDIRECT_originalPath} ^(.+)$
RewriteRule ^ - [E=originalPath:%1]


Regards,
Yann.

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


RE: [users@httpd] Request_URI and ErrorDocument interaction ?

Posted by Cordente Emmanuel <EC...@VOYAGES-SNCF.COM>.
Thank you for the proposition, I tried  it without success.

I've used:
RewriteCond %{ENV:REDIRECT_URL} ^(.+)$
RewriteRule ^ - [E=originalPath:%1]

RewriteCond %{ENV:originalPath} ^$
RewriteRule ^ - [E=originalPath:%{REQUEST_URI}]

ErrorDocument 404 /pagenotfound

In the rewrite log I see something strange:
 [11/Sep/2017:13:27:18 +0200] [myvhost/sid#1df93xx][rid# 7f98e8154870/initial] (5) setting env variable 'originalPath' to '/nothing'
 [11/Sep/2017:13:27:18 +0200] [myvhost/sid#1df93xx][rid# 7f98e80aced8/initial/redir#1] (5) setting env variable 'originalPath' to '/pagenotfound'

The 1st line is what we wanted, but I don't understand the second line.
It's like the internal redirect of the ErrorDocument run again the rewrite rule like if it is a brand new request in another context (without the env variable defined before)

Any idea ?

Emmanuel

-----Original Message-----
From: Yann Ylavic [mailto:ylavic.dev@gmail.com] 
Sent: samedi 9 septembre 2017 21:35
To: users@httpd.apache.org
Subject: Re: [users@httpd] Request_URI and ErrorDocument interaction ?

Hi,

On Wed, Sep 6, 2017 at 1:54 PM, Cordente Emmanuel <EC...@voyages-sncf.com> wrote:
>
> Why the Request_URI environment variable is change by the 
> ErrorDocument treatment ?

The ErrorDocument handling is an internal redirect which changes the URI internally (hence REQUEST_URI) and runs the SetEnvIf again...

The original URI is placed in REDIRECT_URL, though.

>
> Is there a way to get the real request path, either with rewriterule 
> and ErrorDocument ?

I'd try something like (untested):

RewriteCond %{ENV:REDIRECT_URL} ^(.+)$
RewriteRule ^ - [E=originalPath:%1]

RewriteCond %{ENV:originalPath} ^$
RewriteRule ^ - [E=originalPath:%{REQUEST_URI}]

but there's probably a better way to do it.


Regards,
Yann.

---------------------------------------------------------------------
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: [users@httpd] Request_URI and ErrorDocument interaction ?

Posted by Yann Ylavic <yl...@gmail.com>.
Hi,

On Wed, Sep 6, 2017 at 1:54 PM, Cordente Emmanuel
<EC...@voyages-sncf.com> wrote:
>
> Why the Request_URI environment variable is change by the ErrorDocument
> treatment ?

The ErrorDocument handling is an internal redirect which changes the
URI internally (hence REQUEST_URI) and runs the SetEnvIf again...

The original URI is placed in REDIRECT_URL, though.

>
> Is there a way to get the real request path, either with rewriterule and
> ErrorDocument ?

I'd try something like (untested):

RewriteCond %{ENV:REDIRECT_URL} ^(.+)$
RewriteRule ^ - [E=originalPath:%1]

RewriteCond %{ENV:originalPath} ^$
RewriteRule ^ - [E=originalPath:%{REQUEST_URI}]

but there's probably a better way to do it.


Regards,
Yann.

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