htaccess Canonical
# http://socreativedigital.com/7-htaccess-file-examples-that-work-for-seo-2013-05-04
# The first issue I resolved with htaccess was that of the canonical website address.
# I had not much of an issue with this before Nibbler, as you can set the canonical
# address using Googles webmaster tool, which I had done, but that only works for
# Google, and not the other search engines like Yahoo and Bing.
#
# Searching for the correct code for this resulted in a bit of trial and error,
# there are different ways it can be done and occasionally the code i found was
# incorrect or missing parts. I tried several bits of code and each time uploaded
# it onto my server via FTP (ASCII not Binary) and then tested it with Nibbler to
# see if it was working. Eventually I found the code that worked which is below:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yourwebsite\.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.yourwebsite.co.uk/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.yourwebsite.co.uk/$1 [R=301,L]
# The htaccess file has a code all of its own. You can get all the information from
# The Apache Software Foundation website but in all honesty unless you understand the
# technicalities of it all, its very hard to make heads or tails of, but when it works
# it works, and Nibbler likes it!
#
# The above code works if you want to redirect your visitors to the www. version of
# your website, the code also redirects the index.html pages to the correct canonical
# address, but if you want it to redirect to your naked website address then you put this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.yourwebsite\.co.uk$ [NC]
RewriteRule ^(.*)$ http://yourwebsite.co.uk/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://yourwebsite.co.uk/$1 [R=301,L]
# There appears to be no SEO benefit for using www or non-www (naked) domains as long
# as you use one or the other to avoid duplicate content, its up to you. But before
# choosing you might want to read this article regarding the issue. WWW vs non-WWW for
# your Canonical Domain URL – Which is Best and Why?