Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 gets passed to the proxy server which then routes the request to 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.

share|improve this question
up vote 1 down vote accepted

From your comment on my previous answer I gather that you are using apache as a forwarding proxy (ProxyRequests On). You can use mod_rewrite to proxy pass through specific URL's.

You probably got something like this in your apache config:

ProxyRequests On
ProxyVia On
<Proxy *>
   Order deny,allow
   Allow from xx.xx.xx.xx

Then you have to add the following in order to proxy-pass all requests to to

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule /foo(.*)$$1 [P,L]

What this does is:

  • When a request is made to host the RewriteRule will fire
  • This rule substitutes /foo to
  • The substitution is handed over to mod_proxy (P)
  • Stop rewriting (L)

Example result:

  • Browser is configured to use your apache as proxy server
  • It requests
  • Your apache will rewrite this to
  • It will request this page from the responsible webserver
  • Return the result to the browser as
share|improve this answer
Perfect, this is exactly what I wanted to achieve. Only issue with your recommendation is that I needed to use a '%' instead of a '$' in front of '{HTTP_HOST}' in order for RewriteCond to trigger. Thanks much! – LearningIT Apr 29 '10 at 8:19

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 virtual host will be requested from and rewritten by apache:

NameVirtualHost *:80
<VirtualHost *:80>

     <Proxy *>
            Order deny,allow
            Allow from all
     ProxyPass /
     ProxyPassReverse /
share|improve this answer
Thanks much, but I was targeting a different scenario. Here is what I want to enable: a) browser makes HTTP request for, which passes to proxy server for handling b) proxy server sees and based on a pre-determined mapping, forwards the HTTP request to instead c) proxy server receives HTTP response from and forwards to browser (which basically thinks it just received an HTTP response to its HTTP request to Does that clarify? – LearningIT Apr 28 '10 at 2:59
For the sake of self-documentation, if the www part is omitted in the ProxyPassReverseCookieDomain directive, the domains should start with a dot. – Bram Schoenmakers Jun 4 '10 at 11:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.