Redirect all requests to a canonical domain
A website may have several different aliases. Your site may have a .com, .org and a .net domain. Perhaps you, like us, even have other aliased domains.
For www.leveltendesign.com, getlevelten.com and level10design.com both point to the same site.
There are more than just search related reasons to use a canonical domain. If you use SSL or have use authentication, you will want to restrict all visitors to a specific domain.
Cookies are confined to a domain. Since cooking are used for user authentication, this will pose problems for aliased domains. Imagine if you were to visit www.leveltendesign.com and log in as yourself. Now imagine that another user uses www.level10design.com. If that user writes a post and links to content withing the site (say level10design.com/blog, you will be redirected to level10design.com/blog. But you are authenticated for www.leveltendesign.com. You are on the same site, seeing same content, but you'll find yourself logged out.
You can add the directive below to your default site configuration file to redirect traffic to all domains pointing to your server's IP address that do not have their own vhost to a specific domain.
With this method, when you register a domain and manage the DNS entry for the domain you only need to point it to the servers IP address. You will not need to make any server changes.
Try it out:
visit
leveltendesign.com
www.level10design.com
www.getlevelten.com
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.leveltendesign.com$ [NC]
RewriteRule ^(.*)$ http://www.leveltendesign.com$1 [L,R=301]
Since this is in your default configuration file, you can sill use vhost and have other domains (for us, atrium.leveltendesign.com) go to a different directory on the server.
Drupal will have support for rewriting in .htaccess. I strongly recommend against putting rewrites in your Drupal site's .htaccess file. Each time you upgrade to a newer release of Drupal you will need to ensure that your .htaccess modifications are not overridden. By placing this in your site's Apache config file you will not run into site upgrade issues.
photo credit: 23am.com