Apache as reverse proxy for multiple destinations and one default destination

Solution 1:

Wrap your ProxyPass references in a <VirtualHost> definition, like this:

<VirtualHost *:*>
ProxyPreserveHost On
ProxyPass / http://192.168.111.2/
ProxyPassReverse / http://192.168.111.2/
ServerName hostname.example.com
</VirtualHost>

Create two separate ones with the ServerNames you want, then another without ServerName or the Proxy options defined (just DocumentRoot). Put that one last.

More info here.

Solution 2:

Small impovement to Warren Seine's answer (missed "app/" in the first RewriteRule (....127.0.0.1/$1 [P....) )

RewriteRule         ^/app/(.*) http://127.0.0.1/$1 [P,L]

must be

RewriteRule         ^/app/(.*) http://127.0.0.1/app/$1 [P,L]

So, summing up - In case when all your links are distributed among several hosts (accurately as in your case) try this:

ProxyPreserveHost   On
RewriteEngine       On

RewriteRule         ^/appX/(.*) http://x.x.x.x:8000/$1 [P,L]
ProxyPassReverse    /appX/      http://x.x.x.x:8000/
RewriteRule         ^/appY/(.*) http://y.y.y.y:8000/$1 [P,L]
ProxyPassReverse    /appY/      http://y.y.y.y:8000/
RewriteRule         ^/(.*)      http://127.0.0.1:8000/$1 [P,L]
ProxyPassReverse    /           http://127.0.0.1:8000

In case when you need to spread your links at the one host (with different ports & BaseURLs)

ProxyPreserveHost   On
RewriteEngine       On

RewriteRule         ^/appX/(.*) http://127.0.0.1:8001/appX/$1 [P,L]
ProxyPassReverse    /appX/      http://127.0.0.1:8001/appX
RewriteRule         ^/appY/(.*) http://127.0.0.1:8002/appY/$1 [P,L]
ProxyPassReverse    /appY/      http://127.0.0.1:8002/appY/
RewriteRule         ^/(.*)      http://127.0.0.1:8000/$1 [P,L]
ProxyPassReverse    /           http://127.0.0.1:8000