Apache ProxyPassReverse with parameters from request

apache-2.2mod-rewrite

I've a situation where I want to redirect everything that starts with /app to an internal server. Basically the idea is that Apache will work as a reverse proxy doing the following conversion:

http://external/app -> http://myserver:1082/myapp

I was able to do it using Rewrite, as follows:

  RewriteCond %{REQUEST_URI} ^/app
  RewriteRule ^/app(.*)$ http://myserver:1082/myapp$1 [L,P]

  ProxyPassReverse /app http://myserver:1082/myapp

It works fine. The issue is that now I'm gonna have a language preffix on the URL, but no on the application. So I need the following redirection:

http://external/app -> http://myserver:1082/myapp
http://external/en/app -> http://myserver:1082/myapp
http://external/pt/app -> http://myserver:1082/myapp

While this can be done with the rewrite, I have a problem with the proxyPassReverse. Because basically I need to do a dynamic ProxyPassRever that, depending on the actual URL request by the user, changes the Location

ProxyPassReverse /en/app http://myserver:1082/myapp
ProxyPassReverse /pt/app http://myserver:1082/myapp
ProxyPassReverse /app http://myserver:1082/myapp

It would be something like

ProxyPassReverse ${preffix}/app http://myserver:1082/myapp

Is it possible to do that?

Best Answer

From ProxyPathReverse:

When used inside a section, the first argument is omitted and the local directory is obtained from the .

From Location:

The URL may use wildcards. In a wild-card string, ? matches any single character, and * matches any sequences of characters. Extended regular expressions can also be used, with the addition of the ~ character.

So you should be able to use:

<Location /[a-z]+/app>
    ProxyPathReverse http://myserver:1082/myapp
</Location>