Link to home
Start Free TrialLog in
Avatar of andYetAnotherLoginName
andYetAnotherLoginName

asked on

ANYBODY? WE STILL NEED THAT!

...am giving away everything I have.

layout: we'd like to use mod_proxy with mod_rewrite together to replace hostname before submitting it to upstream proxy.

that is, user types, for example, http://www.icq.com/; then we rewrite it with http://10.0.2.7/.

so far we've managed to set up mod_proxy (it worx like any normal proxy). Now, when we add
<IfModule mod_rewrite.c>
 RewriteEngine On

 RewriteCond     %{HTTP_HOST}     ^.*\.icq\.com
 RewriteRule  ^/(.*)$  http://10.0.2.7/$1  [R]
</IfModule>

nothing happens. what should be correct rewrite rules/conditions ?
Avatar of rjkimble
rjkimble

What are you trying to accomplish exactly? You can incorporate proxying into your rewrite rules, but I have never done that. It seems to me that the point of mod_proxy is to make the browser think it's talking to one server while behind the scenes the conversation is being handed off to a second server. The point of mod_rewrite is to explicitly redirect the browser from the first server to the second.

You might consider adding an "L" to the "R" in your RewriteRule. Otherwise mod_rewrite keeps on looking for other rules to match, which is probably not what you want.
Avatar of andYetAnotherLoginName

ASKER

We need to "filter" out some of addresses and replace them with ours before submitting to mod_proxy.
How about using the P flag as a rewrite rule?

For example:

<IfModule mod_rewrite.c>
 RewriteEngine On

 RewriteCond     %{HTTP_HOST}     ^.*\.icq\.com
 RewriteRule  ^/(.*)$  http://10.0.2.7/$1  [R,L]

 RewriteRule (your proxy rules goes here)
</IfModule>

The Apache docs for mod_rewrite give examples on using the P flag.
In this case 10.0.2.7 is local address. But, even if it was not, mod_rewrite is envolved before mod_proxy and the key problem is, as rewrite log shows, that no changes to URL are made.

Thus, it is about conditions/rules.
Are you sure that mod_rewrite is involved before mod_proxy? The order in which the modules are loaded affects the order in which they process requests. Is it possible that mod_proxy is firing first and sending the request along its way before mod_rewrite gets a chance to chime in? You might try inverting the order in which the two modules are loaded in httpd.conf (or whatever included file the import statements occur).
When I do that, rewrite log gets empty - because all URLs were processed by mod_proxy, I think. So I guess it is not the reason.
we have solved this. the key was "proxy:" part.

RewriteCond %{HTTP_HOST} ^(www\.)icq\.com [NC]
RewriteRule   ^proxy:http://www.icq.com/(.*)  http://205.188.248.121/$1 [P]

i want my points refunded.
That's one I haven't seen before. You deserve your points back. Please don't ask to delete the question, however. The answer is good to know.
ASKER CERTIFIED SOLUTION
Avatar of Lunchy
Lunchy
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial