When using RewriteRule in <If> context, the pattern is matched against the file system path instead of the URI path: httpd.conf: <IfModule rewrite_module> RewriteEngine on LogLevel alert rewrite:trace8 <If "true"> RewriteRule ^(.*)$ http://example.localhost/?$1 [R=302,L] </If> </IfModule> Request: http://example.com/test Expected response: Redirect to http://example.localhost/?/test Received response: Redirect to http://example.localhost/?/usr/www/htdocs/test Rewrite log: [Fri Mar 15 10:52:15.994467 2019] [mpm_winnt:notice] [pid 4976:tid 408] AH00455: Apache/2.4.38 (Win64) OpenSSL/1.0.2r configured -- resuming normal operations [Fri Mar 15 10:52:26.369060 2019] [rewrite:trace2] [pid 10744:tid 1128] mod_rewrite.c(483): [client 127.0.0.1:62192] 127.0.0.1 - - [localhost/sid#1d7798][rid#290ff40/initial] init rewrite engine with requested uri /test [Fri Mar 15 10:52:26.369060 2019] [rewrite:trace1] [pid 10744:tid 1128] mod_rewrite.c(483): [client 127.0.0.1:62192] 127.0.0.1 - - [localhost/sid#1d7798][rid#290ff40/initial] pass through /test [Fri Mar 15 10:52:26.377060 2019] [rewrite:trace3] [pid 10744:tid 1128] mod_rewrite.c(483): [client 127.0.0.1:62192] 127.0.0.1 - - [localhost/sid#1d7798][rid#290ff40/initial] [perdir *If/] applying pattern '^(.*)$' to uri '/usr/www/htdocs/test' [Fri Mar 15 10:52:26.377060 2019] [rewrite:trace2] [pid 10744:tid 1128] mod_rewrite.c(483): [client 127.0.0.1:62192] 127.0.0.1 - - [localhost/sid#1d7798][rid#290ff40/initial] [perdir *If/] rewrite '/usr/www/htdocs/test' -> 'http://example.localhost/?/usr/www/htdocs/test'
I can confirm this bug. It makes RewriteRules completely not working inside <If></If> at all if working with non local path, for example in reverse proxy usage. Also %{QUERY_STRING} is empty.
I have recently run into what I think is this issue with the following config: <If "true" > RewriteEngine On RewriteCond "%{REQUEST_URI}" !^/___proxy_me/ RewriteRule ^/(.*)$ "/___proxy_me/$1" # [L,NE,B=%\ |:] </If> ProxyPass /___proxy_me/ "http://backend/" upgrade=websocket What ends up happening is the backend server receives a url like: %{document_root}%{request_uri} From logs of two apache servers main proxying to backend running in docker: backend-1 | 172.21.0.2 - - [24/Mar/2024:10:49:02 +0000] "GET /usr/local/apache2/htdocs/ HTTP/1.1" 404 196 main-1 | 172.21.0.1 - - [24/Mar/2024:10:49:02 +0000] "GET / HTTP/1.1" 404 196 backend-1 | 172.21.0.3 - - [24/Mar/2024:11:06:25 +0000] "GET /usr/local/apache2/htdocs/test-url.html HTTP/1.1" 404 196 main-1 | 172.21.0.1 - - [24/Mar/2024:11:06:25 +0000] "GET /test-url.html HTTP/1.1" 404 196 for repoduction using latest docker image version: https://github.com/cseufert/apache-proxy-test-2