How to Use ProxyMatch or ProxyPassMatch with Regex for mapping multiple Context paths

user3140950 picture user3140950 · Nov 24, 2015 · Viewed 10.7k times · Source

I am using IBM's IHS Webserver built on top of Apache Web server Version 2.2.4.

My requirement is to proxy pass a various Context path using regular expression in match.

I tried using ProxyPassMatch but I get below error

ERROR: "Invalid ProxyPass|ProxyPassMatch parameter. Parameter must be in the form 'key=value'"

<LocationMatch "^/(ae/en|ar/en|ar/es|at/en|au/en|be/en|br/en)/">
Order Allow,Deny
Allow from all
ProxyPass http://www.xyz.com.au:80/au/en/      #(should keep varying as per the regex matched in location match )
ProxyReverse http://www.xyz.com.au:80/au/en/   #(should keep varying as per the regex matched in location match )
</LocationMatch>

Kindly advice how this can be achieved.

Regards Sridhar

Answer

MKaama picture MKaama · Nov 6, 2016

If you put ProxyPassMatch iside a LocationMatch section, the first argument to ProxyPassMatch (regex) must be omitted. It will come from LocationMatch. Example from my (working) configuration:

<VirtualHost *:80>
ServerName gopal.lv
ServerAlias gopal.lv www.gopal.lv
ProxyPreserveHost On

<LocationMatch "^/(img|js|css|att|thumb|banner)/(.+)$">
#Note: only 1 argument here
ProxyPassMatch "http://192.168.1.11/$1/$2"
</LocationMatch>

#Note we have 2 arguments here
ProxyPassMatch "^/(img|js|css|att|thumb|banner)/(.+)$" "http://192.168.1.11/$1/$2"
ProxyPass / http://192.168.1.12/

</VirtualHost>

Otherwise, you get the error

ERROR: "Invalid ProxyPass|ProxyPassMatch parameter. Parameter must be in the form 'key=value'"

It is documented here: https://httpd.apache.org/docs/trunk/mod/mod_proxy.html#proxypass