Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Httpd Wiki" for change 
notification.

The following page has been changed by slive:
http://wiki.apache.org/httpd/Recipes/CanonicalHostNames

New page:
= Canonical HostNames =

Many sites map a variety of hostnames to the same content. For example, 
www.example.com, example.com and www.example.net may all refer to the same 
site. It is best to make sure that, regardless of the name clients use to 
access the site, they will be redirected to a single, canonical hostname. This 
makes the site easier to maintain and assures that there will be only one 
version of the site in proxy caches and search engines.

== Using Virtual Hosts ==

{{{
NameVirtualHost *:80

<VirtualHost *:80>
  ServerName www.example.net
  ServerAlias example.com
  Redirect permanent / http://www.example.com/
</VirtualHost>

<VirtualHost *:80>
  # Canonical host
  ServerName www.example.com
  DocumentRoot /usr/local/apache/htdocs
</VirtualHost>
}}}

== Using mod_rewrite ==

{{{
# For sites running on a port other than 80
RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://www.example.com:%{SERVER_PORT}/$1 [L,R]

# And for a site running on port 80
RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://www.example.com/$1 [L,R]
}}}

Reply via email to