Re: best way to modify a URL

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

 



Oliver Schoenborn wrote:

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!

The main aspect is that you understand what is going on.
Now you can fly with your own wings.
In the second part of my answer, I was trying to avoid doing an external redirect, because : - it is less efficient in terms of bandwidth : you add a round-trip to the browser and back - it is less efficient in terms of your server : you have to process 2 consecutive requests, instead of just one - even for a fleeting moment, the browser is aware of the redirection, while if you do the redirection entirely inside of Apache, the browser never sees anything, and thinks the whole time that it is talking to dodo.foo.com

Also, in your example above, for me instinctively the last 3 rules look like you are doing some extra work that should not be necessary :
- you test if the host name is "dodo.foo.com"
- then you modify the URL to add this hostname in front of the URL
- only to strip it out again and redirect to "foo.com/bar/" with a proxy rule
It may all work, but it seems terribly heavy.
Maybe I'm wrong though.


Considering your latest answer, I am also now inclined to think that using <VirtualHost> sections would be much cleaner.




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