-1

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?

Cœur
  • 37,241
  • 25
  • 195
  • 267
The Surrican
  • 29,118
  • 24
  • 122
  • 168

1 Answers1

1

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

Femi
  • 64,273
  • 8
  • 118
  • 148
  • 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 05 '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 05 '11 at 15:57
  • 1
    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 05 '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 05 '11 at 16:07
  • 1
    Odd. Well, minor point from http://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 `RewriteRule`s). – Femi Jun 05 '11 at 16:10
  • you are right again! about the redirect! so now i have all parts together and working and have to adjust them to my specific needs! thanks a lot! i would like to give you a thousand upvotes if i could. – The Surrican Jun 05 '11 at 16:13
  • Glad to help. Figured it would be some small oversight like that. – Femi Jun 05 '11 at 17:07