[thelist] mod_rewrite and proxy rules for Apache

John DeStefano john.destefano at gmail.com
Wed Apr 9 09:20:09 CDT 2008

I run into this problem all the time, and recent discussion regarding  
mod_rewrite has rekindled my interest.  I often need to use a single  
Apache server to proxy "back-end" servers on other machines.  	I  
usually do something like this with ProxyPass:
ProxyPass /server1 http://backend-server1/something
ProxyPassReverse /server1 http://backend-server1/something
ProxyPass /server2 http://backend-server2/something
ProxyPassReverse /server2 http://backend-server2/something

I use mod_rewrite at times to do something similar:
RewriteRule /server1$ /server1/ [R]                      # "trailing  
slash" fix
RewriteRule /server1/(.*)$ http://backend-server1/something/$1 [P]   #  
also tried [P,L] to make this the "last" rule processed

Sometimes these work fine, and other times (often when the back-end  
applications are similar or the same) the page contents of "server2"  
come through but the page's images and CSS are lost.  When I try to  
track down the problem using Apache's logs, I see that the server  
serves the content from "server2" but tries to load the other pieces  
from "server1".  Another indication is often that the links on the  
page are to "server1" resources, not to "server2".

Any pointers on the right way to do this would be appreciated.


More information about the thelist mailing list