You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Paul Kuykendall <pk...@gmail.com> on 2007/07/10 19:56:04 UTC

[users@httpd] Rewrite Rule using HTTP Header information

Hi,

I am trying to get a rewrite rule working that will take the value
from an HTTP header and use the value to create a new target
destination for the HTTP request.  An example of what I'm trying to do
follows:

Original HTTP request being sent to http://myhost.domain/ containing the header
MyRoutingID: SOME_VALUE

This needs to be rewritten and sent to http://myhost.domain/SOME_VALUE

This will then be forwarded using a reverse proxy to
http://apphost.domain/SomeLocation/SomeApplication

I know that this may seem like a really convoluted way of doing
things, but our clients don't actually know where they are sending
requests to, other than the server name.  The receiving server has to
pass the request along based on the routing ID; however, the routing
ID isn't actually part of the final destination URL.  The routing ID
-> destination URL mapping will be generated and included as an
external config file loaded into the Apache configuration at load.

So far what I have is the following:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

ProxyRequests Off
ProxyPass /SOME_VALUE http://apphost.domain/SomeLocation/SomeApplication

<Location /SOME_VALUE>
    ProxyPassReverse /SomeLocation/SomeApplication
</Location>


LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteCond %{HTTP:MyRoutingID} (.*)
RewriteRule .* - [E=ROUTING_ID:$1]

RewriteRule ^/(.*) http://myhost.domain/%{ROUTING_ID} [P,L]

The proxy config is working fine.  The RewriteRule however, does not.
Thanks for any help on getting the RewriteRule working.

Thanks!

/Paul

---------------------------------------------------------------------
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] Rewrite Rule using HTTP Header information

Posted by Paul Kuykendall <pk...@gmail.com>.
On 7/10/07, Vincent Bray <no...@gmail.com> wrote:
> On 11/07/07, Paul Kuykendall <pk...@gmail.com> wrote:
> > I am trying to get a rewrite rule working that will take the value
> > from an HTTP header and use the value to create a new target
> > destination for the HTTP request.  An example of what I'm trying to do
> > follows:
> >
> > Original HTTP request being sent to http://myhost.domain/ containing the header
> > MyRoutingID: SOME_VALUE
> >
> > This needs to be rewritten and sent to http://myhost.domain/SOME_VALUE
> >
> > This will then be forwarded using a reverse proxy to
> > http://apphost.domain/SomeLocation/SomeApplication
>
> I don't understand this part. How can you forward one url to another?

I may have used the wrong terminology.

>
> > I know that this may seem like a really convoluted way of doing
> > things, but our clients don't actually know where they are sending
> > requests to, other than the server name.  The receiving server has to
> > pass the request along based on the routing ID; however, the routing
> > ID isn't actually part of the final destination URL.  The routing ID
> > -> destination URL mapping will be generated and included as an
> > external config file loaded into the Apache configuration at load.
> >
> > So far what I have is the following:
> >
> > LoadModule proxy_module modules/mod_proxy.so
> > LoadModule proxy_http_module modules/mod_proxy_http.so
> >
> > ProxyRequests Off
> > ProxyPass /SOME_VALUE http://apphost.domain/SomeLocation/SomeApplication
> >
> > <Location /SOME_VALUE>
> >     ProxyPassReverse /SomeLocation/SomeApplication
> > </Location>
> >
> >
> > LoadModule rewrite_module modules/mod_rewrite.so
> > RewriteEngine On
> > RewriteCond %{HTTP:MyRoutingID} (.*)
> > RewriteRule .* - [E=ROUTING_ID:$1]
> >
> > RewriteRule ^/(.*) http://myhost.domain/%{ROUTING_ID} [P,L]
> >
> > The proxy config is working fine.  The RewriteRule however, does not.
> > Thanks for any help on getting the RewriteRule working.
>
> These two parts of your config do different and conflicting things.
> Are you expecting the rewrite to the address containing the ROUTING_ID
> to be then forwarded by your ProxyPass? If so, why the double
> indirection? In any case there's a few errors in the rule, this might
> work better.
>
> LoadModule rewrite_module modules/mod_rewrite.so
> RewriteEngine On
> RewriteCond %{HTTP:MyRoutingID} (.*)
> # Not that captures from conditions are reading using %n rather than $n
> RewriteRule ^/(.*) http://myhost.domain/%1 [P,L]
>
>
> --
> noodl
>

Late yesterday I found a solution to the problem I was having.

<IfModule !mod_proxy.c>
LoadModule proxy_module modules/mod_proxy.so
</IfModule>

<IfModule !mod_proxy_http.c>
LoadModule proxy_http_module modules/mod_proxy_http.so
</IfModule>

<IfModule !mod_rewrite.c>
LoadModule rewrite_module modules/mod_rewrite.so
</IfModule>

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTP:RequestIDHeader} ^(.*)
    RewriteRule ^/$ http://%{HTTP_HOST}/%{HTTP:RequestIDHeader} [P,L]

</IfModule>

<IfModule mod_proxy.c>
    ProxyRequests Off

    ProxyPass /REQUEST_ID_VALUE http://AppServer/AppName/AppServlet
    <Location /REQUEST_ID_VALUE>
        ProxyPassReverse http://AppServer/AppName/AppServlet
    </Location>

</IfModule>

Where REQUEST_ID_VALUE is the header value of RequestIDHeader.  I know
that it seems like a lot of work, but the application being supported
is based off a legacy system that has no knowledge of exactly where
the message is being sent to.  We're using Apache essentially as a
low-cost layer-7 traffic management system, dipping into the message
to pull the routing information from the HTTP message header.

Thanks, though, for the reply!

/Paul

---------------------------------------------------------------------
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] Rewrite Rule using HTTP Header information

Posted by Vincent Bray <no...@gmail.com>.
On 11/07/07, Paul Kuykendall <pk...@gmail.com> wrote:
> I am trying to get a rewrite rule working that will take the value
> from an HTTP header and use the value to create a new target
> destination for the HTTP request.  An example of what I'm trying to do
> follows:
>
> Original HTTP request being sent to http://myhost.domain/ containing the header
> MyRoutingID: SOME_VALUE
>
> This needs to be rewritten and sent to http://myhost.domain/SOME_VALUE
>
> This will then be forwarded using a reverse proxy to
> http://apphost.domain/SomeLocation/SomeApplication

I don't understand this part. How can you forward one url to another?

> I know that this may seem like a really convoluted way of doing
> things, but our clients don't actually know where they are sending
> requests to, other than the server name.  The receiving server has to
> pass the request along based on the routing ID; however, the routing
> ID isn't actually part of the final destination URL.  The routing ID
> -> destination URL mapping will be generated and included as an
> external config file loaded into the Apache configuration at load.
>
> So far what I have is the following:
>
> LoadModule proxy_module modules/mod_proxy.so
> LoadModule proxy_http_module modules/mod_proxy_http.so
>
> ProxyRequests Off
> ProxyPass /SOME_VALUE http://apphost.domain/SomeLocation/SomeApplication
>
> <Location /SOME_VALUE>
>     ProxyPassReverse /SomeLocation/SomeApplication
> </Location>
>
>
> LoadModule rewrite_module modules/mod_rewrite.so
> RewriteEngine On
> RewriteCond %{HTTP:MyRoutingID} (.*)
> RewriteRule .* - [E=ROUTING_ID:$1]
>
> RewriteRule ^/(.*) http://myhost.domain/%{ROUTING_ID} [P,L]
>
> The proxy config is working fine.  The RewriteRule however, does not.
> Thanks for any help on getting the RewriteRule working.

These two parts of your config do different and conflicting things.
Are you expecting the rewrite to the address containing the ROUTING_ID
to be then forwarded by your ProxyPass? If so, why the double
indirection? In any case there's a few errors in the rule, this might
work better.

LoadModule rewrite_module modules/mod_rewrite.so
RewriteEngine On
RewriteCond %{HTTP:MyRoutingID} (.*)
# Not that captures from conditions are reading using %n rather than $n
RewriteRule ^/(.*) http://myhost.domain/%1 [P,L]


-- 
noodl

---------------------------------------------------------------------
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