Re: Port-based vhosts

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

 



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.

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]



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



[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