Google has yet to clean up the canonicalization problem that arises when the www version of your site gets indexed along with the non-www version (i.e. http://www.digimode.co.uk& http://digimode.co.uk).
Here is the code that can be used in the .htaccess file to redirect successfully and ethically.
301 non-www to www
<code>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^seobook.com [NC]
RewriteRule ^(.*)$ http://www.seobook.com/$1 [L,R=301]
</code>
The ‘(*.)$’ says that we’ll take anything that comes after http://digimode.co.uk and append it to the end of ‘http://www.digimode.co.uk’ (thats the ‘$1′ part) and redirect to that URL. For more grit on how this works checkout a good regular expressions resource or two.
Note: You only have to enter ‘RewriteEngine On’ once at the top of your .htaccess file.
Alternately you may chose to do this 301 redirect from
in the Apache config file httpd.conf.
<code>
<VirtualHost 67.xx.xx.xx>
ServerName www.digimode.co.uk
ServerAdmin webmaster@digimode.co.uk
DocumentRoot /home/digimode/public_html
</VirtualHost>
<VirtualHost 67.xx.xx.xx>
ServerName digimode.co.uk
RedirectMatch permanent ^/(.*) http://www.digimode.co.uk/$1
</VirtualHost>
</code>
Note that often webhost managers like CPanel would have placed a ‘ServerAlias’ seobook.com in the first VirtualHost entry which would negate the following VirtualHost so be sure to remove the non-www ServerAlias.
301 www to non-www
Finally the www 301 redirect to non-www version would look like:
<code>
RewriteCond %{HTTP_HOST} ^www.digimode.co.uk [NC]
RewriteRule ^(.*)$ http://digimode.co.uk/$1 [L,R=301]
</code>
Good Luck!


