Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

Example:

fitzefatze.sourcedomain.com should get the content of:

fitzefatze.targetdomain.com

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 *.sourcedomain.com

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

ProxyPass / $1.targetserver.com

share|improve this question

2 Answers 2

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)$ http://backend.example.com:8000$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)$ http://backend.example.com:8000/$1

I don't know if it will accept http://$1.targetserver.com 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 ^/(.*)$ http://%1.targetdomain.com/$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

 
discard

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.