RE: best way to modify a URL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Thanks Andre for the detailed explanations. Looks like I have it figured out: 

From: André Warnier [aw@xxxxxxxxxx]
>>
>> 1. Client goes to http://dodo.foo.com:
>>   A. server changes this to http://foo.com/bar
>>   B. server returns content (which will be http://foo.com/bar/index.html)
>>   C. client sees the content in browser
>>   D. AND the client's browser shows the URL (in Location text field) as being http://dodo.foo.com (rather than http://foo.com/bar/index.html)
>>
>
> As someone else indicated previously, this is a standard feature of
> mod_proxy.

Yes. However, AFAICT the ProxyPass cannot be given conditions as with RewriteRule. So if I have 

ServerName foo.com
ServerAlias dodo.foo.com

then the ProxyPass/Reverse will be applied to requests to either domains, which is not what I want (requests to foo.com should be processed as usual as there are other web apps served from there).

>> 2. Client clicks on a link that is on the page just received:
>>   A. the href will be, say, http://foo.com/bar/someotherpage.html
>>   B. server returns content
>>   C. client sees the content in browser
>>   D. AND the client's browser shows the URL (in Location text field) as being 
>>      http://dodo.foo.com/someotherpage.html (rather than 
>>      http://foo.com/bar/someotherpage.html)
>
> So I will rectify A above as follows :
>
>   A. the href will be http://dodo.foo.com/someotherpage.html

You're right, the href is actually "/someotherpage.html" so it will be as you say. 

> And that will work, because of the Proxy rules above (he will get the
> content of the file "http://foo.com/bar/someotherpage.html"; )

In order to apply the proxying just for dodo.foo.com only, I use a rewrite rule. Here is what I have so far, seems to work completely: 

RewriteCond   %{HTTP_HOST}                 ^dodo\.foo\.com$
RewriteRule   ^/bar/(.*)               /$1    [R,L]

RewriteCond   %{HTTP_HOST}                 ^dodo\.foo\.com$
RewriteRule   ^(.+)                        %{HTTP_HOST}$1          [C]
RewriteRule   ^dodo\.foo\.com/(.*)    http://foo.com/bar/$1   [P]

The [R,L] of first rule causes a redirect to client and the rule processing ends so client will just make a new request with the /bar/ stripped out, AND client browser will show the redirected URL. The [P] in second rule will cause proxying, but only for requests to dodo.foo.com, so client will NOT see that foo.com/bar is really the URL used. Time will tell if there are any corner cases that this doesn't cover. But boy, that rewrite module is powerful stuff!

Oliver
---------------------------------------------------------------------
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@xxxxxxxxxxxxxxxx
   "   from the digest: users-digest-unsubscribe@xxxxxxxxxxxxxxxx
For additional commands, e-mail: users-help@xxxxxxxxxxxxxxxx



[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux