I'm setting up a RewriteRule, but at the moment it just redirects the browser. What I want is proxying, so that the user does not recognise the url changed behind.

I came around the P flag:

RewriteRule ^/(.*) ... [P]

which is the same as a ProxyPass statement.

Now: how do I make a ReverseProxyPass statement within my rewrite rule?


You don't, but you can often make it work the way you need it anyway.

First off, make sure you need to use RewriteRule instead of simply ProxyPass. The rule you've provided is quite simple; if you don't have some RewriteCond logic in front if it, then you can just as easily use ProxyPass.

In any case, let's take an example where you're doing something like this:

RewriteRule ^/proxied-location/(.*)$ http://backend/$1 [P]

So, you're taking a request for http://your-apache-server/proxied-location/something.html and sending it to the backend without the /proxied-location/ part of the URL.

A redirecting (30x) response would not include the /proxied-location/ part of the URL, despite the fact that the client needs that in order to access the other resource through the proxy. That's what ProxyPassReverse handles. So, just add a configuration like this:

ProxyPassReverse /proxied-location/ http://backend/

The config only applies on requests where the proxy backend handles the response, so the "conditions" that you've applied with mod_rewrite effectively still apply.

Make sense?

  • Ok cool thanks for your explain. But I still struggle how to use this. Eg: I have a condition, based on this cond I want every request to be mapped to an entirely new address. Regardless of what the requested url is. eg RewriteRule ^/whatever/ http://myhomeserver:8080/manager. This would forward any request to my apache manager console. How should I now write the ProxyPassReverse statement, as the destination url does not have anything in common with the request (anyhow the requested url should still be visible to the user)? – membersound Aug 6 '12 at 20:21
  • @membersound Well, I'd recommend against that, since the manager webapp uses resources other than just /manager; pages the user would visit are /manager/status or /manager/html/list, and it loads resources like /manager/images/asf-logo.gif. But in a theoretical situation where you'd only want to allow access to a single, specific resource, that'll still work fine: ProxyPassReverse /whatever http://myhomeserver:8080/manager – Shane Madden Aug 7 '12 at 0:59
  • the manager console is just an example for testing as i do not have a webapp yet. of course 8 will not expose it to the user. thx – membersound Aug 7 '12 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.