Bug 64117 - Apache is not logging original URL %<U or original query %<q when using RewriteEngine
Summary: Apache is not logging original URL %<U or original query %<q when using Rewri...
Status: NEW
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_log_config (show other bugs)
Version: 2.4.41
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-02-05 16:12 UTC by Michal Ambroz
Modified: 2020-02-05 19:28 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michal Ambroz 2020-02-05 16:12:21 UTC
Hello,
when using RewriteEngine it seems that the original URL path of the request (%<U) is not logged. 

Tested on apache 2.4.6 present in RHEL7 and 2.4.41 in Fedora 31.

No matter if I use %U or %<U or %>U in the LogFormat, the output written to the log file is always containing the url after rewriting. Same applies for the query string (%q %<q %>q).

According the documentation http://httpd.apache.org/docs/current/mod/mod_log_config.html it should be possible to use "<" and ">" modifiers to distinguish between original and final value, but it doesn't work for %<U and %<q when using the RewriteEngine. The only formatting string which holds the original URL seems to be %r.

For example having application, which redirects all URL and query parameters to handler index.php :
    RewriteEngine On    # Turn on the rewriting engine
    #===== Pass requests for nonexisting files to index.php
    RewriteCond "/var/www/html/%{REQUEST_FILENAME}" !-f
    RewriteRule "(.*)" "/index.php?path=$1" [PT,QSA]

So user requesting http://test.com/hello/world?param1=value1 will be actually processed by http://test.com/index.ph?path=/hello/world&param1=value1 

I would like to log Custom log with the original URL, but it doesn't work ... for example:
LogFormat "%h %l %u %t \"%m http://%{Host}i%<U%<q %H\" %>s %b" common_full_url 


Best regards
Michal Ambroz
Comment 1 Eric Covener 2020-02-05 16:32:58 UTC
In non-directory/htaccess context, rewrites don't trigger internal redirects, which is what those special characters unwind.  Without PT, these rewrites just change the mapped filename. With PT, they change the URL-path %U in-place.

I think if you want to preserve it, you need to set it aside into an envvar.
Comment 2 Michal Ambroz 2020-02-05 18:53:30 UTC
Hello Eric.
I do not think I follow you with setting the  envvar?
Some example please?

My understanding is that %<U should preserve the original url as received from the client.
Comment 3 Eric Covener 2020-02-05 19:28:30 UTC
(In reply to Michal Ambroz from comment #2)
> Hello Eric.
> I do not think I follow you with setting the  envvar?
> Some example please?

In your rewriterule something like [PT,E=ORIG_URL:$0]

> 
> My understanding is that %<U should preserve the original url as received
> from the client.

```
The modifiers "<" and ">" can be used for requests that have been internally redirected to choose whether the original or final (respectively) request should be consulted.
```

It is specifically for internal redirects (which are a type of "sub-request"). Anything that just modifies the main/original request will not generate an internal redirect, so there is no separate "original"/"final" request.