Archive for the 'Apache' Category

Canonical Hostname

Monday, April 2nd, 2007

You can force your website to be accessed through a canonical hostname by forcing a redirect from other hostnames in .htaccess or httpd.conf:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^canonical\.host\.name [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*)$      http://canonical.host.name/$1 [C,L,R=301]
RewriteRule ^$           http://canonical.host.name/ [L,R=301]