Bug 57056 - Rewrite port is taken into hostname
Summary: Rewrite port is taken into hostname
Alias: None
Product: Apache httpd-2
Classification: Unclassified
Component: mod_rewrite (show other bugs)
Version: 2.4.10
Hardware: PC Windows XP
: P2 major (vote)
Target Milestone: ---
Assignee: Apache HTTPD Bugs Mailing List
Depends on:
Reported: 2014-10-03 20:38 UTC by Danila Galimov
Modified: 2018-08-23 18:39 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Danila Galimov 2014-10-03 20:38:11 UTC
My goal is to write proxy, which will proxy all requests to the VPN.

So, I've written the following configuration:

<VirtualHost *:8121>
  RewriteEngine On

  ErrorLog logs/misc-error_log
  TransferLog logs/misc-access_log

  RewriteRule ^/(.*) http://%{HTTP_HOST}:8121/$1 [P]

However, for some reason, it's not working as expected.

It seems that it tries to resolve '%{HTTP_HOST}:8121' as host name.

Browser answer is

Proxy Error

The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /.

Reason: DNS lookup failure for: n01wmw202:8121

Log error contains the same entry

[Sat Oct 04 07:34:34.123051 2014] [proxy:error] [pid 4004:tid 1260] [client] AH00898: DNS lookup failure for: n01wmw202:8121 returned by /

If I remove ':8121' everything is working as expected.
Comment 1 Danila Galimov 2014-10-03 20:46:56 UTC
It also reproduces if i change it to

  RewriteRule ^/(.*) http://%{HTTP_HOST}:%{SERVER_PORT}/$1 [P]
Comment 2 Christophe JAILLET 2018-08-23 05:02:54 UTC
Unless I missed something, your configuration matches:
> Here are all possible substitution combinations and their meanings:
> Inside per-server configuration (httpd.conf)
> for request ``GET /somepath/pathinfo'':
> [...]
> ^/somepath(.*) http://thishost/otherpath$1 [P] 	doesn't make sense, not supported

at the end of https://httpd.apache.org/docs/2.4/en/mod/mod_rewrite.html#rewriterule.

I tried your configuration with the trunk version. I also get a AH00898, but with another error message.

If I change the port number in the RewriteRule to something different from the one in the VirtualHost, everything seems to work fine.

So, I guess that "*:8121" in VirtualHost and '%{HTTP_HOST}:8121' in RewriteRule are the same, which is not supported as per doc.

So closing as invalid.
Feel free to re-open, if I misunderstood something.
Comment 3 Danila Galimov 2018-08-23 18:03:01 UTC

If if it not supported for now, is it possible to convert this into a feature request? 

It would be very handy to specify a port in case it is different from the virtual host configuration.
Comment 4 Christophe JAILLET 2018-08-23 18:37:33 UTC
If the port is different, it seems to work, according to my testing.

Look at the allowed configuration at the bottom of the link in comment 2.
My understanding of the doc, and according to my tests, is that "thishost" mentioned in the doc means "the host name including its port".
So *:8121 in the VirtualHost and '%{HTTP_HOST}:8121' in RewriteRule matches, and is not a supported configuration.

But *:8121 in the VirtualHost and '%{HTTP_HOST}:8122' in RewriteRule shouldn't match and would refer to :
> ^localpath(.*) http://otherhost/otherpath$1 [P] 	http://otherhost/otherpath/pathinfo via internal proxy
in the doc.

If you could try and confirm, I would update the doc to be more precise.
Comment 5 Christophe JAILLET 2018-08-23 18:39:03 UTC
(and thx for your prompt feed-back on a 4 years old PR!)