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

Let's say I have the following subdomain with its own document root etc:

I want that all requests are proxied to an IP (for instance but they must pass through the server at (assuming monad2 is on this same server).

I have the following (htaccess) config which works up to the subdomain, but fails to proxy any other request...

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)$1 [P]

My problem is that while it does work for (url remains the same), it doesn't work with requests like (url is converted to Note that the latter address shows a directory listing of the proxied server, which is correct, except that the subdomain changed to an ip.

Also, I presume this system will definitely not work for HTTPS requests, correct?

Edit: After some more troubleshooting, I've found exactly when the problem is being caused. Whenever I try to access a directory without the final slash, the proxy fails, and I end up with an IP. Some example:

Original                        | Result
--------------------------------+--------------------------------        |     |      |           <- !  |
share|improve this question
Do you have access to the actual Apache configuration, or just an htaccess file? – Shane Madden Mar 17 '12 at 19:20
@ShaneMadden I have root access, but I kind of preferred using htaccess. I'm perfectly fine with an alternative solution though. – Christian Mar 18 '12 at 16:50
up vote 4 down vote accepted

You need ProxyPassReverse - it catches Location fields in response headers and alters them so that the client will continue talking to the proxy, instead of the backend server.

ProxyPass and ProxyPassReverse cannot be in an .htaccess file - so replace your current rewrite rule with this, which should go inside your <VirtualHost> block for the subdomain:

ProxyPass /
ProxyPassReverse /

As an aside: do not use .htaccess when you can avoid it. Review the Apache documentation on the matter.

In general, you should only use .htaccess files when you don't have access to the main server configuration file.

share|improve this answer
Ah, tried that one but didn't work, probably because I tried it in the .htaccess. Regarding the 'not to use htaccess' part, though it is understandable, everyone knows that it is impractical. .htaccess are just so convenient. Heck, even I that know my own server better than anyone else will take me several minutes to find the right apache config file. That said, thanks a lot for your help...I'll reply soon when I get it working (or break everything up!) ;) – Christian Mar 18 '12 at 18:56
Sounds like you need to do a better job of naming and/or organizing your configs. – Scott Pack Mar 18 '12 at 19:25
OK, it works! Thanks. – Christian Mar 18 '12 at 19:26
@ScottPack Tell that to the guys creating CPanel :( – Christian Mar 18 '12 at 19:26
Add ProxyPreserveHost On to your config to have the host header sent to the PHP server, or use ProxyPassReverseCookieDomain to alter the cookie domain in the response header. – Shane Madden Mar 18 '12 at 20:31

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.