How to Use ProxyMatch or ProxyPassMatch with Regex for mapping multiple Context paths
Solution 1
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
Solution 2
Always use separate lines for comments, and quote the string arguments. There where bug regathering this thing in their bugzila, but I believe you are not using an old version. https://bz.apache.org/bugzilla/show_bug.cgi?id=40439
<LocationMatch "^/(ae/en|ar/en|ar/es|at/en|au/en|be/en|br/en)/">
Order Allow,Deny
Allow from all
#should keep varying as per the regex matched in location match
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/"
</LocationMatch>
Admin
Updated on June 05, 2022Comments
-
Admin almost 2 years
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 errorERROR: "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