Bug 66099 - Error in the documentation for %{REQUEST_URI}
Summary: Error in the documentation for %{REQUEST_URI}
Status: RESOLVED FIXED
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_rewrite (show other bugs)
Version: 2.4-HEAD
Hardware: Other All
: P2 normal (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
URL: https://httpd.apache.org/docs/current...
Keywords: FAQ
Depends on:
Blocks:
 
Reported: 2022-05-31 20:22 UTC by Jörg Reinholz
Modified: 2022-06-01 11:07 UTC (History)
0 users



Attachments
error.log .filtered (1.98 KB, text/plain)
2022-06-01 09:12 UTC, Jörg Reinholz
Details
This show the redirect of the client-side. (3.12 KB, text/plain)
2022-06-01 09:14 UTC, Jörg Reinholz
Details
The config file for the apache (331 bytes, text/plain)
2022-06-01 09:17 UTC, Jörg Reinholz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jörg Reinholz 2022-05-31 20:22:33 UTC
The Doc says:

„REQUEST_URI“
“The path component of the requested URI, such as "/index.html". This notably excludes the query string which is available as its own variable named QUERY_STRING.“

https://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritecond

This not correct.

I have tried and the %{QUERY_STRING} is a part of %{REQUEST_URI} (not only in rewrite-rules, in PHP $_SERVER['QUERY_STRING'] show the same.

Per Definitionem is the query a part of the uri (URI). so shold only the documentation be corrected.

Discussion (in german):

https://forum.selfhtml.org/self/2022/may/30/weiterleitung-von-domain-zu-domain/1799519#m1799519
Comment 1 Eric Covener 2022-06-01 00:54:46 UTC
In my testing the query string is not part of the %{REQUEST_URI} variable resolved by mod_rewrite (or expression-based use)

The REQUEST_URI environment variable passed to CGI and CGI-like handlers has a different value, the one you'd expect based on the name (including the query)

If you think it really contradicts the doc in mod_rewrite in some config please share the most basic config that demonstrates the issue and the resulting rewrite:trace8 and access_log.
Comment 2 Jörg Reinholz 2022-06-01 09:12:32 UTC
Created attachment 38307 [details]
error.log .filtered

The error.log shows explicit:

applying pattern '(.*)' to uri '/'
rewrite '/' -> 'https://home.fastix.org/'
explicitly forcing redirect with https://home.fastix.org/
escaping https://home.fastix.org/ for redirect
copying foo=bar to query string for redirect 
redirect to https://home.fastix.org/?foo=bar [REDIRECT/301]
Comment 3 Jörg Reinholz 2022-06-01 09:14:39 UTC
Created attachment 38308 [details]
This show the redirect of the client-side.
Comment 4 Jörg Reinholz 2022-06-01 09:17:07 UTC
Created attachment 38309 [details]
The config file for the apache
Comment 5 Jörg Reinholz 2022-06-01 09:33:30 UTC
on fastix.de i have only this in a .htaccess - File. This has the same effect: The query (try fastix.org/test?foo=bar) is in the redirect-uri:


RewriteEngine On
RewriteRule (.*) https://www.fastix.org%{REQUEST_URI}
Comment 6 Jörg Reinholz 2022-06-01 09:37:44 UTC
Sorry, there is an error in my descryption:

on fastix.de i have only this in a .htaccess - File. This has the same effect: The query (try fastix.de/test?foo=bar) is in the redirect-uri:


RewriteEngine On
RewriteRule (.*) https://www.fastix.org%{REQUEST_URI}

--- 
chanched „try fastix.org/test?foo=bar“ to „try fastix.de/test?foo=bar“
Comment 7 Yann Ylavic 2022-06-01 09:46:15 UTC
The query-string is used because the target URI is a full URI (starting with "https:") and mod_rewrite preserves the query-string for full URIs.

If you want to avoid that, use the [QSD] flag (instead of [QSA]).
Comment 8 Jörg Reinholz 2022-06-01 09:54:58 UTC
> „The query-string is used because the target URI is a full URI“

I think this should also be noted in the documentation in this case. Because the statement "This notably excludes the query string" conveys that the query is never part of '%{REQUEST_URI}'.
Comment 9 Yann Ylavic 2022-06-01 10:35:12 UTC
(In reply to Jörg Reinholz from comment #8)
> the statement "This notably excludes the query string" conveys that the
> query is never part of '%{REQUEST_URI}'.

It's actually true that the query-string is never part of %{REQUEST_URI} in mod_rewrite, the query string generated by your redirect rule comes from the rule itself, not the content of the %{REQUEST_URI} variable.

Nevertheless, it probably should be included in the docs (though not relative to %{REQUEST_URI}).
Comment 10 Yann Ylavic 2022-06-01 11:07:09 UTC
Note added in r1901487.