[ACCEPTED]-Retain original request URL on mod_proxy redirect-mod-proxy

Accepted answer
Score: 28

If you're running Apache >= 2.0.31 then 8 you might try to set the ProxyPreserveHost directive as described 7 here.

This should pass the original Host header 6 trough mod_proxy into your application, and 5 normally the request URL will be rebuild 4 there (in your Servlet container) using 3 the Host header, so the schema location 2 should be build using the host and path 1 infos from "before" the proxy.

(Posted here too for the sake of completeness)

Score: 7

Here is another alternative if you would 9 like to retain both the original host name 8 and the proxied host name.

If you are using 7 mod_proxy disable ProxyPreserveHost in the Apache configuration. For 6 most proxy servers, including mod_proxy, read 5 the X-Forwarded-Host header in your application. This identifies 4 the original Host header provided by the 3 HTTP request.

You can read about the headers 2 mod_proxy (and possible other standard proxy 1 servers) set here:

http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

Score: 1

You should be able to do a mod_rewrite in 11 apache to encode the full URL as a query 10 parameter, or perhaps part of the fragment. How 9 easy this might be depends on whether you 8 might use one or the other as part of your 7 incoming queries.

For example, http://external.foo.bar/MyApplication might get 6 rewritten to http://external.foo.bar/MyApplication#rewritemagic=http://external.foo.bar/MyApplication which then gets passed into 5 the ProxyPass and then stripped out.

A bit 4 of a hack, yes, and perhaps a little tricky 3 to get rewrite and proxy to work in the 2 right order and not interfere with each 1 other, but it seems like it should work.

More Related questions