Search code examples
apachemod-rewriteproxyurl-rewritingmod-proxy

How to rewrite urls that go through apaches mod_proxy


I have configured my apache 2.2 server as a simple forward proxy using mod_proxy and mod_proxy_http.

When the client requests a URL of the following format:

http://specific.host.com/specific?specificarg1=(.+)&specificarg2=(.+)&specificarg3=specificvalue

to be requested in a rewritten form where the values for specificarg1 and specificarg2 get replaced by values defined in my server config.

It would be also possible not to use regex but to rewrite a specific url to another specific url, but i would prefer with regex matching.

So after reading the documentsations for mod_rewrite, mod_proxy and so I tried something like the following to get some sort of rewrite working at all:

RewriteRule .* http://www.google.com/ [P,L]

just like that in the server config, nothing gets rewriten when surfing over the proxy

<VirtualHost *:80>
ServerName domain-i-tried-to-surf-to.com
`RewriteRule .* http://www.google.com/ [P,L]
</VirtualHost>

no luck either

ProxyPass(Reverse) / http://www.google.com
ProxyPass(Reverse) /path/i/tried/to/surf/to http://www.google.com

no luck with that too

ProxyRemote * http://www.google.com

no luck as well

I also tried to put rewrite rules into proxymatch directives but I am just unable to rewrite a url. Can somebody point me in the right direction?


Solution

  • You first need to add a RewriteEngine on statement at the very beginning to even get mod_rewrite to process any rules.