Category Archives: apache-regexp

How to use regular exp in Apache’s Location?

I have urls with id, like:

customers/2248/contracts
customers/553/subscribers
customers/search
customers/bob
cusomters/moreUrls

I need to redirect urls like customers/{customerId}/contracts to one port (server), but customers/* and customers/{customerId}/subscriber to another.

I am trying ~ this in httpd.conf:

<Location customers/\d+/contracts>
 Header set MyHeader "regexp passed" #for debug
 ProxyPass http://server.com:YYY
 ProxyPassReverse http://server.com:YYY
<Location>

<Location customers>
 ProxyPass http://server.com:XXX
 ProxyPassReverse http://server.com:XXX
<Location>

I expect, that urls like customers/{id}/contracts will be redirected to server.com:YYY, but others (customers/* and customers/{id}/subscribers) will be redirected to server.com:XXX. Actually, */contracts is not being redirected. Also, I don't see header "MyHeader" what I'd added, as you see, in location for url */contracts.

What I am doing wrong?