The solution ended up being a combination of several different tools in apache:
- The use of a text file to map each subdomain to the appropriate IP
- The interpolation of environment variables to access the subdomain in the proxy redirection (had to use
ProxyPassInterpolateEnv On
and theinterpolate
keyword at the end of theProxyPass
andProxyPassReverse
statements)
Apache:
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from localhost
</Proxy>
RewriteEngine On
ProxyPassInterpolateEnv On
RewriteMap subdomains txt:/directory/clients.txt
RewriteCond %{HTTP_HOST} ^(.*)\.application\.com
RewriteRule ^ - [E=SERVER_NAME:${subdomains:%1}]
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ %{REQUEST_URI}/ [R]
ProxyPass / http://${SERVER_NAME}/ interpolate
ProxyPassReverse / http://${SERVER_NAME}/ interpolate