Tag Archives: URL canonicalization

301 redirect WWW to non WWW (.htaccess)

In some cases you’ll want to make sure and re-direct all usage of WWW to you non WWW web address. This will also consolidate your homepage link juice to make sure that only 1 url is getting credit rather than 2. The formal term for this is “URL canonicalization”

01- Open your .htaccess file in notepad

02- paste in the following code at the top of the document (replace yoursite.com with your own site address)

RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]

03– save and overwrite your previous file (in root)

Note: you’ll also want to add the additional 301 redirects for the following reasons:

A site can have up to 4 variations. Though what that means is that your link popularity could also be divided between these variations.

Assuming your site address is http://yoursite.com, you”ll want to have the other 4 variations redirected to http://yoursite.com

Those other variations could be:

(Now its important to note this level of scrutiny should only be limited to your home page)
(you should also write your code depending on how your end desired URL should look)

Now to further the above code, I also suggest adding the following to and END RESULT like this:

RewriteCond %{HTTP_HOST} ^www.yoursite.com [NC]
RewriteRule ^(.*)$ http://yoursite.com/$1 [L,R=301]

redirect 301 /index.html http://yoursite.com/
redirect 301 /index.htm http://yoursite.com/

Continue reading 301 redirect WWW to non WWW (.htaccess)