Take the 2-minute tour ×

When using apache to reverse proxy, is it possible to forward http://somesite.com/ and http://somesite.com/foo to different servers? Say one goes to http://internalserver1/ and the other goes to http://internalserver2/foo

I can obviously just drop further down the path (ie http://somesite/bar) but its not desirable.

share|improve this question
Take a look at Nginx as a reverse proxy over Apache, it's relatively new but has already surpassed LightHttp in use and it very fast and lightweight. –  Swish Aug 6 '09 at 18:02
add comment

2 Answers

up vote 3 down vote accepted

it seems that order of directives in your vhost is important. and yes - you can achieve what you need. i just run test for:

ProxyPass /q http://host.one.com/img/
ProxyPass / http://another.host/

and it worked fine - all requests [ except those directed to /q/something ] ware proxied to another.host. those for /q/whatever - went to host.one.com

share|improve this answer
hmm, this didnt work for me, i ended up with the same issue without order - all links went to (in your example) another.host did you include ProxyPassReverse? –  Devnull Jul 22 '09 at 21:05
@ANervousTwitch i'm sorry to hear it but this actually does work for me. no - i do not have ProxyPassReverse, only two lines for proxy: "ProxyPass /q stackoverflow.com/"; and "ProxyPass / serverfault.com/"; after that. –  pQd Jul 22 '09 at 21:19
@ANervousTwitch - i'm using apache 2.2.9-10 from debian. –  pQd Jul 22 '09 at 21:19
I agree that this should work. –  radius Jul 22 '09 at 22:58
add comment

You should be able to do this using mod_rewrite. It evaluates conditions in order and you can specify the [L] flag to make it stop processing further rules.

RewriteEngine On
RewriteRule /foo/(.*) http://internalserver2/foo/$1 [P,L]
RewriteRule /(.*)     http://internalserver/$1 [P]

Full mod_rewrite documentation is at http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

share|improve this answer
add comment

Your Answer


