Apache2 LocationMatch with simple regular expression
How to Proxy an URL of the this type:
http://example.com/folder/username/api/some-chars
to an internal server?
I have looked for a long time in the apache2 LocationMatch official docs hoping to find a solution how to write correctly the regular expressions that will do the job until I managed to come out with a working solution.
And here is what I have come up with:
<LocationMatch "/folder/([a-z]+)/api/(.*)">
ProxyPass http://internal-machine/$0
ProxyPassReverse http://internal-machine/$0
</LocationMatch>
To brake the above regular expression and the URL that it will match, the rule will match:
– any URL that starts with /folder/;
– look for a follow up of any sequence of characters containing lowercase letters a-z (a-z) with length > 1;
– look for an exact match of ‘/api/’;
– followed by any number and any kind of followup characters;
– the matched URLs will be forwarded to server http://internal-machine/;
– with query string $0=/folder/([a-z]+)/api/(.*)