I am trying to build a reverse proxy using Apache.
My goal is to proxy all requests of the form <subdomain>.domain.com/file.html to www.domain.com/<subdomain>/file.html.
I somehow need to capture the <subdomain> of the original URL and use it to construct the target URL.
I assume that I need an Apache directive that can match regular expressions on the whole URL, instead of the part of the url after %{HTTP_HOST}, since my target URL contains the original URL’s subdomain. For this reason I can’t use the ProxyPassMatch directive, since it only matches the part of the URL after %{HTTP_HOST}.
Another alternative is to use as many VirtualHost sections as my subdomains. But of course this solution doesn’t make sense, since my subdomains will keep increasing.
Any tips on how to tackle this?
Ok, I managed to solve it using Rewrite rules.
Basically what happens is this:
RewriteCondmatches all incoming requests whose URL matches .domain.com/RewriteRuleproxies the request to the URLhttp://www.domain.com/%1/%2, where%1and%2are the subdomain and request uri of the original request, respectively.