This seems like a super-basic question but I am having a hard time tracking down a straightforward solution, so appreciate any help and patience with me on this:
I want to configure my Apache proxy server to redirect certain URLs so that, for example, a web browser HTTP request for www.olddomain.com gets passed to the proxy server which then routes the request to www.newdomain.com which sends a response to the proxy server which then passes it back to the web browser.
Seems so simple, yet I don't see how to achieve this on Apache. I know Squid/Squirm offer this functionality so am guessing I am missing something really basic. I know I can use RewriteRule to dynamically modify the URL and pass it to the proxy server, but I effectively want to do the reverse, whereby the proxy server receives the original URL, applies the RewriteRule, and then forwards the HTTP request to the new URL.
Hope that makes sense. Thanks in advance for any help.
From your comment on my previous answer I gather that you are using Apache as a forwarding proxy (
ProxyRequests On
). You can usemod_rewrite
to proxy pass through specific URL's.You probably got something like this in your Apache config:
Then you have to add the following in order to proxy-pass all requests from
www.olddomain.com/foo
towww.newdomain.com/bar
:What this does is:
www.olddomain.com
, theRewriteRule
will fire./foo
tohttp://www.newdomain.com/bar/
.mod_proxy
(P
).L
).Example result:
www.olddomain.com/foo/test.html
.www.newdomain.com/bar/test.html
.www.olddomain.com/foo/test.html
.If I understand you correctly, you probably want to look at: mod_proxy in combination with name-based virtual hosts
Here is a little example of what this might look like. All requests from the www.olddomain.com virtual host will be requested from www.newdomain.com and rewritten by apache: