Setting up a Primary URL

This post is more for my own reference as I always forget the syntax.

When you have several domains but want to have one of them set up as a primary I generally set up Apache like so:


<VirtualHost *:80>
ServerName domain.com
ServerAlias *.thedomain.com *.thedomain.ca *.domain.ca
DocumentRoot /var/www/domain/
</VirtualHost>

Then in the root folder set up a .htaccess with the following:


Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com$
RewriteRule ^(.*) http://www.domain.com/$1 [L,R=301]