You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by DM <do...@yahoo.co.uk> on 2006/11/14 17:27:12 UTC

[users@httpd] mod_rewrite & mod_proxy

Hi,

I was presented with the seemingly straightforward task of converting URLs such as:

http://cellularmanagerpp.aliant.net/myProg?param1=val1&url=http://cellularmanagerpp.aliant.net&param3=val3

to:

http://erie:9090/myProg?param1=val1&url=http://erie:9090&param3=val3


Attempt 1
---------------
Use a reverse proxy to forward the request to erie:9090 and use mod_rewrite to change the value of the "url" query parameter.

####################### httpd.conf #######################
RewriteEngine on

# This changes the 'url' query param
RewriteCond %{QUERY_STRING}  ^(.*)url=http%3A%2F%2Fcellularmanagerpp%2Ealiant%2Enet(.*)$
RewriteRule ^(.*)$           $1?%1url=http\%3A\%2F\%2Ferie\%3A9090%2 [P]

ProxyRequests Off

<Proxy *>
        Order deny,allow
        Allow from all
</Proxy>

# This should redirect the request to erie:9090
ProxyPass / http://erie:9090
ProxyPassReverse / http://erie:9090/
#######################################################


The re-writing appeared to work fine, but it seemed the rewritten URLs weren't being sent to the proxy.


Attempt 2
---------------

Use mod_rewrite to change the entire URL (i.e. not just the parameter value), and a reverse proxy to change the hostname in the response

####################### httpd.conf #######################

RewriteEngine on

# This changes the 'url' query param
RewriteCond %{QUERY_STRING}  ^(.*)url=http%3A%2F%2Fcellularmanagerpp%2Ealiant%2Enet(.*)$
RewriteRule ^(.*)$           $1?%1url=http\%3A\%2F\%2Ferie\%3A9090%2 [NE]

# This changes the hostname
RewriteRule ^/(.*)$          http://erie:9090/$1 [P,QSA,L]

ProxyRequests Off

<Proxy *>
        Order deny,allow
        Allow from all
</Proxy>

# This makes the response look like it came from Apache, rather than erie:9090
ProxyPassReverse / http://erie:9090/
#######################################################

This appears to work. However, because I'm using mod_rewrite, only the request line is changed. For example, the value of the "referrer" header still references "cellularmanagerpp.aliant.net".


Anyway, my questions are these:

- Why didn't the proxying work with the rewritten URLs in Attempt 1?
- Is there a way to achieve my goal which also rewrites the headers?
- In httpd.conf it possible to set a variable whose value is "erie", then reference this variable, so that I don't have to repeat "erie" in multiple places?


Many thanks in advance,
DM

Send instant messages to your online friends http://uk.messenger.yahoo.com 

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] mod_rewrite & mod_prox

Posted by Joshua Slive <jo...@slive.ca>.
On 11/14/06, DM <do...@yahoo.co.uk> wrote:

> This appears to work. However, because I'm using mod_rewrite, only the request line is changed. For example, the value of the "referrer" header still references "cellularmanagerpp.aliant.net".
>

Hmmm... I think that will be the case with ProxyPass as well.  This is
not a redirect, it is a proxy.  Most (non-connection-level) headers
will remain untouched.

>
> Anyway, my questions are these:
>
> - Why didn't the proxying work with the rewritten URLs in Attempt 1?

You can try adding the [PT] flag to the RewriteRule to let processing
pass to the next url-mapping phase.

> - Is there a way to achieve my goal which also rewrites the headers?

I doubt it.

> - In httpd.conf it possible to set a variable whose value is "erie", then reference this variable, so that I don't have to repeat "erie" in multiple places?

There are several different modules that allow you to use variables in
a flexible way in config files.  See http://modules.apache.org/ and
look for things like mod_macro.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org