Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule with P (Proxy) flag is not working

RewriteRule, ProxyPreserveHost

         

mikeip

9:33 pm on Dec 4, 2008 (gmt 0)

10+ Year Member



Hi,

I am trying to make my RewriteRule work preserving the hostname of the Apache server. In my RewriteRule I want to get the request redirected to the external Web server while preserving the hostname of the Apache server in the URL. Here is the issue:
If I have [P] defined in the RewriteRule :

RewriteRule ^test(.*)$ [target.example.com:80...] [P,L]

I am getting the Apache hostname preserved in the URL , but the "test" string is not removed from the target URI. So my URL (after RewriteRule) looks like : [apacheserver.example.com...] defined in the $1>.... . Basically the whole URI is getting redirected to the target server (w/o expected removal of "test")

If I remove [P] flag from the RewriteRule, the rule works fine although I am not getting the Apache host name preserved in the URL.

Any help or pointers are highly appreciated,
Thanks and regards,
Mike

jdMorgan

2:41 am on Dec 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's weird... Your rule is fine, although [L] is redundant when used with [P].

What happens if you do this?


RewriteRule ^test(.*)$ $1 [C]
RewriteRule (.*) http://target.example.com:80/$1 [P]

I'd be interested to know what version of Apache you're running, and what OS and OS version it's running under.

Jim

mikeip

2:09 am on Dec 9, 2008 (gmt 0)

10+ Year Member



Hi Jim,

You suggestion didn't work. Still the same result. I am running Apache 2.2.10 on Mac OSX 10.5.5 but I tried the same rule on the Apache 2.2.10 running on Windows and on the 2.2.9 on the Mac OSX. It didn't work either.

Regards,
Mike

jdMorgan

2:41 am on Dec 9, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd be looking for some kind of interaction going on here then, because in the two-step chained rule I posted, there is no way that "test" would survive into the URL sent to the back-end machine. The consistent results of your testing on different machines and OSes rules out a bad regular-expressions-library installation, so something else is going on here. Unfortunately, I have no idea what it could be.

Jim

[edited by: jdMorgan at 2:42 am (utc) on Dec. 9, 2008]

Caterham

6:54 pm on Dec 17, 2008 (gmt 0)

10+ Year Member



I tried to reproduce that behavior (there were some modifications around mod_proxy), but I can't. Is there anything else, which may influence a reverse proxy?

I thought that there could went sthg. wrong while the proxy-handler canonicalises the URL using r->uri somewhere (which should still contain the initial value of that request_rec), but that's not the case.

Switching

LogLevel
do debug might be a good idea as well since mod_proxy et al. will log a lot in that case. A
RewriteLog
should show you the processing of the part done by mod_rewrite.

By default, until apache 2.3, apache 2.x should compile with and statically link against a shipped copy of the PCRE library (scrlib folder) unless configured with

--with-pcre=...
while compiling not to do so.