Re: Port-based vhosts

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

 



On Tue, 10 Mar 2009, Krist van Besien wrote:

On Tue, Mar 10, 2009 at 2:24 AM, Charles Sprickman <spork@xxxxxxxx> wrote:
So in short, this does work, until I get into the murky area of keeping the
URL consistent in the browser.  For example, let's take "www.foo.com". I
always want visitors to see "www.foo.com" in the browser URL field.  If I
set "UseCanonicalName On" in the virthosts, the ServerName seems not to be
enforced like it is with traditional IP or name-based hosting.  If I point
"giantpornstash.blah.com" at the IP that "www.foo.com" resolves to, the user
will browse the site with "giantpornstash.blah.com" in the browser address
field.  It is my (limited) understanding that this should not happen with
the ServerName and UseCanonicalName settings properly configured, and
basically can't happen with Name-based virthosts (host header doesn't
match).

The only way that you can change what appears in the browser's address
bar is by forcing a redirect, so the browser requests the site again
from the correct name.  If you don't force a redirect if a site is
requested with the wrong name than this wrong name will stay visible
in the browser.

OK. That makes perfect sense. At this point, my main concern is actually understanding how this works. When I was reading the docs on "UseCanonicalName" (http://httpd.apache.org/docs/2.2/mod/core.html#usecanonicalname) I noticed that reference is made to "self-referential" URLs. Under what conditions does Apache then get involved and alter the URL? Just redirects? I understand a common redirect is just adding a trailing slash when the user does not supply it. What are some other common cases? Who's call is it when a simple static site uses non-absolute URLs for all the links? Is the browser building the fully-qualified links or apache (I suspect the former)?

What you need to do is check what's in the "Host" header, and if it
doesn't match the ServerName send a redirect.

RewriteEngine On
RewriteCond %{HTTP_HOST}   !^www\.foo\.com [NC]
RewriteCond %{HTTP_HOST}   !=""
RewriteRule ^/(.*)         http://www.foo.com/$1 [L,R=301]

Excellent. It may be a challenge for me to incorporate this into the search-engine-friendly rewrite rules that Joomla uses, but I'll give it a spin on a staging box and see what happens.

What kind of performance impact, in general, do simple rewrites like this impose on a busy server?

Thanks,

Charles



HTH,

Krist


--
krist.vanbesien@xxxxxxxxx
krist@xxxxxxxxxxxxx
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

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


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