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

I want to reverseproxy a subdomain to another domainname with the same hostname.

Example: should get the content of:

This should be dynamic, so that every hostname will be translated to the target domain name.

I guess this could be done with the ProxyPass directive but I don't know how to get the host name for the target:

something like this ServerName *

ProxyRequests Off
<Proxy *>
    AddDefaultCharset off
    Order deny,allow
    Allow from all #

ProxyPass / $

share|improve this question

There's the ProxyPassMatch directive, but it does specify the following restriction:

The URL argument must be parsable as a URL before regexp substitutions (as well as after). This limits the matches you can use. For instance, if we had used

ProxyPassMatch ^(/.*.gif)$$1

in our previous example, it would fail with a syntax error at server startup. This is a bug (PR 46665 in the ASF bugzilla), and the workaround is to reformulate the match:

ProxyPassMatch ^/(.*.gif)$$1

I don't know if it will accept http://$ as a valid URL before substitution -- try it out and let us know!

As mentioned by Shane, you could also use mod_rewrite, but you should be aware that the proxying done by mod_rewrite does not use connection pooling -- each new request will create a new proxy connection on the fly. Therefore you will not be able to benefit from the persistent connection pooling done by ProxyPass, nor will you able to fine-tune its behaviour with the per-connection-pool options that ProxyPass provides (keepalive, timeout, connectiontimeout, retry, min/max, etc.).

Note that there doesn't appear to be a matching ProxyPassReverseMatch directive for either alternative.

share|improve this answer
Excellent first post. Keep up the good work! – slm Dec 22 '12 at 23:12

To do this, you'll need to use mod_rewrite..

RewriteCond %{HTTP_HOST} ^(.*)\.sourcedomain\.com$
RewriteRule ^/(.*)$$1 [P,L]

..and keep in mind, ProxyPassReverse won't work here so any 30x response will not be translated.

share|improve this answer
Thank you very much!! This is working fine. – Mario Schweda Dec 23 '12 at 13:30

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.