Take the 2-minute tour ×

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:


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]

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?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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

share|improve this answer
probably should have mentioned that i took care of all modules and enginges to be fired up. i am thinking that none of the rules matches because the origin of the webpages it not the local server. i think the directives are intended to handle resources in the back "behind" the current host. without the need that the user has confiugred a proxy whatsover. what i want is to rewrite urls that are requested through a forward proxy, but where the origin of those is NOT the local server. i know its a bit off the mainstream but i think it should be possible, but the docs are quite vague on this... –  The Surrican Jun 5 '11 at 15:55
a "workaround" would be force requests on the specific domains to another server by overwiring the ip in /etc/hosts, Then this other server has a vhost vhost container configured to listen on it and then processes the rewrite rules. but i kind of dont want to involve a second server... –  The Surrican Jun 5 '11 at 15:57
Ah. So clarification then: you have server A serving as a proxy to server B, and you're putting the rewrite expressions in server A? If that's right can you edit your question and include your entire config text for server A, just so I can be certain what's what, because that should work just fine, but I can't tell from the snippets you provided what's going on. –  Femi Jun 5 '11 at 16:06
i am sorry you were right. i had to include rewriteengine on INSIDE the proxymatch directive. now my url gets redirected using a location redirect altough i included the [P] flag. any ideas on that? i have proxyrequests on in the serverconfig, not inside the proxymatch direcive (this gives an error) - i am editing the questino to make eveyrthing more clear –  The Surrican Jun 5 '11 at 16:07
Odd. Well, minor point from httpd.apache.org/docs/2.2/rewrite/flags.html#flag_p: if you are using a P, then you don't need an L as it is implied. And I'm guessing your location redirect is actually coming from the server you are proxying, not from mod_rewrite (unless you have an errant R directive in one of your RewriteRules). –  Femi Jun 5 '11 at 16:10
show 2 more comments

Your Answer


