ProxyPass to variable external domain

Topics: Developer Forum, User Forum
Sep 20, 2011 at 9:21 AM


I am very new to regex and IIRF and I need help with rewriting the external domain (for ProxyPass) based on the script name in the initial request.

Perhaps an example may help. This is basically what I want to happen but it does not work.

ProxyPass    ^/(.*)$    http://{SCRIPT_NAME}:8880/$1

If this is not possible is there any way to re-write the external domain name based on a variable from the initial request?

Any help is greatly appreciated!




Sep 20, 2011 at 10:26 AM

Ok, so i actually got this working, but it wasn't the desired result. It actually re-wrote using every script name instead of just the initial.

My next guess is to use a sub-domain and use that prefix as the external. Anyone have an example of how I can separate out the first and second subdomains?

For example (in pseudo code):

ProxyPass     http://$sub1.$sub2.$    http://$sub1.$sub2:8880/$1

Thanks again!

Sep 20, 2011 at 4:44 PM
Edited Sep 21, 2011 at 2:14 PM
# match on a 3-part hostname, in order to capture the subdomains
RewriteCond %{HTTP_HOST}   ^([^\.]+)\.([^\.]+)\.([^\.]+)\.com$
ProxyPass ^/(.*)$   http://*1.*2:8888/$1 
Sep 20, 2011 at 8:11 PM
Edited Sep 20, 2011 at 8:12 PM

Genius!  Thanks so much.  I should note that it did not work with the $, so I changed it to a # and added an extra set for a 4-part domain.

       RewriteCond #{HTTP_HOST}   ^([^\.]+)\.([^\.]+)\.([^\.]+)\.com$


Sep 21, 2011 at 2:07 PM

great, glad it worked.  Your use of # is ....non-standard.  I don't know how that would be possible, because the % with curly-braces is hard-coded into the IIRF source code as a way to evaluate server variables.

Unless you are using an old version of IIRF, or a modified version of IIRF, then I don't  know how that would work.