Reverse Proxy homepage only

apache-2.2proxypass

I regularly use Apache to reverse proxy to other servers using ProxyPass and ProxyPassReverse. I have been doing this by top level folder. But now I have the requirement to put the site's home page on a new CMS server.

What is the best way to reverse proxy the home page only (for requests: GET / HTTP/1.1 ) without affecting every request?

I guess I can list every directory and top level page on the server with the ! directive. But surely there is a better way.

All help gratefully received.

Best Answer

ProxyPass directives are processed in order of the first match, simply list the one to the CMS last e.g.

ProxyPass /app1 http://app1.example.org/app1
ProxyPassReverse /app1 http://app1.example.org/app1
ProxyPass /app2 http://app2.example.org/app2
ProxyPassReverse /app2 http://app2.example.org/app2

ProxyPass / http://cms.example.org/
ProxyPassReverse / http://cms.example.org/

Alternatively hope for a well behaved CMS where only the main landing page is in the root and all scripts, images and other content is in appropriate subdirectories:

# Redirect requests to www.example.org/ to www.example.org/index.html
RewriteRule  ^/$                 /index.html

ProxyPass /index.html http://cms.example.org/index.html

ProxyPass /css http://cms.example.org/css
ProxyPassReverse /css http://cms.example.org/css    
ProxyPass /img http://cms.example.org/img
ProxyPassReverse /img http://cms.example.org/img
Related Topic