2

I'm moving a web application to a new set of servers in a different data center. As part of a beta period, I want to configure the old server as a reverse proxy for some requests, based on a pattern in the URL.

For example, if someone requests:

http://old.example.com/foo/bar?q=1

... I want to transparently give them the results of

http://new.example.com/foo/bar?q=1

Redirects won't work, as this is used as an API and some clients don't properly follow redirects (fixing the clients isn't an option). Also, this needs to work for both GET and POST requests.

The list of URLs to proxy would be selective, e.g. so that only the "foo/*" requests would be proxied, and the others would just be served by old.example.com until the final cutover.

Is mod_proxy the right way to go? I can't find any examples that appear to:

  1. Allow selective proxying (e.g. /foo/bar is proxied but /baz/ham is not),
  2. Pass along the entire path and querystring, and
  3. Keep the POST body and all HTTP headers in tact.

Any help would be greatly appreciated.

1 Answer 1

3

From what you describe a simple:

 ProxyPass /foo/ http://new.example.com/foo/

should work. All headers and GET/POST queries should just be forwarded fine. You may need a matching ProxyPassReverse depending on your setup and needs. If you need more control on which URLs are proxied you can use:

 ProxyPassMatch [regex] [url]

The official documentation does a pretty good job at explaining things. If you've tried to proxy like this and it doesn't work a new question with more specific details on what you've tried and what the exact issue is may get you better results.

1
  • Thanks! I can't do this in a .htaccess is the only problem, but I found that a RewriteRule with the [P] flag works as well. Dec 19, 2012 at 20:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .