Apache Proxy – Redirect URLs with Specific String

httpdmod-proxyPROXYproxypassreverse-proxy

I have a server which runs 2 applications. I am using a public IP address and I want to parse the url in a way if a specific text occurs the call is redirect to a specific port. In my case I want that if the url contains:

  • /myapp1/a1 -> port 82
  • /myapp2/a2 -> port 81

examples:
Supposing my public ip is p.u.b.l, my private ip is p.r.i.v, the following URLs should be resolved by the server in this way:

http://p.u.b.l./myapp1/a1/something -> http://p.r.i.v.:82/myapp1/a1/something
http://p.u.b.l./myapp2/a2/something -> http://p.r.i.v.:81/myapp2/a2/something

I am trying to configure Apache in a way to provide reverse proxy. Following my configuration in site-availables, also added in site-enabled:

ServerName p.r.i.v

ProxyPassMatch "/myapp1/a1(.*)$" "http://p.r.i.v:82/myapp1/a1/$1"
ProxyPassReverse "/myapp1/a1(.*)$" "http://p.r.i.v:82/myapp1/a1/$1"

ProxyPassMatch "/myapp2/a2(.*)$" "http://p.r.i.v:81/myapp2/a2/$1"
ProxyPassReverse "/myapp2/a2(.*)$" "http://p.r.i.v:81/myapp2/a2/$1"

But the redirect is not working. What am I missing? Please consider the direct access to the private resource works, meaning http://p.r.i.v:81/myapp2/a2/something, but the http://p.u.b.l/myapp2/a2/something is not resolved

Any help is appreciated
Thanks
Simone

Best Answer

the issue is resolved. In the proxied url there was an encoded char, which needed a proper definition. In this case, I added AllowEncodedSlashes On and nocanon next to the ProxyPass and ProxyPassReverse rules.

Thanks Simone