How To Set Canonical URL : Preffered Domain www or non www

October 16, 2010

I was wondering what I want to write in this blog about SEO for the first time. So I decided to talk about preferred domain or canonical URL for homepage. Many bloggers/webmasters have known about this canonical url issues,canonical pages and canonical tag pagination,but there are some who don’t know or maybe wondering what is preferred domain, how to set this up and what is the advantage of using www prefix or without it. What to do if we change previous canonical URL.Well,I don’t know if there is advantage  using www prefix or without it.But the problem is when you want to change your previous preferred domain into www or without www and you need to make standart URL to make sure you don’t get penalized because of duplicated content.Remember that the www and the non www version of a site is a different URL for search engine.As a proof their both statistics not exactly the same.Now If you only change it through your wordpress setting,many visitors from the search engine will find 404 page unless you redirecting it using 301 server side.So,you need to set this imediately with simple step.I’ll explain after this to redirect using .htaccess file at the bottom of this post.

When the first time after installing wordpress, you will probably go to Dashboard==>Profile then to Setting==>General  .In this page, you will find whether to set your wordpress installation directory  and URL using www or no.Simply choose what url you preffer to be crawled by the search engine.There is a good SEO plugin which can set canonical url for post or page,it will add an attribute rel=”canonical” so the search engine know this canonical url is important and higher priority among other link .Even some great themes have a built in feature about this.But the problem doesn’t stop here in case somehow you want to change your preffered domain/canonical URL for your homepage from http://yoursite.com to http://www.yoursite.com ,but of course you do not want to loose all the statistic data,indexed backlinks of your previous preffered domain and search result for your site keep running smoothly.

Now,if you have a Google  account,simply go to Webmaster Tools in order to set this up. So the search engine will synchronizing your statistic  data, backlinks, and the search results and automatically detecting and redirecting your previous preferred domain into the new one. You have to verify your site ownership first by methods given.I prefer html method.Just upload the downloaded html file to your home directory,click the link and you all set and verified.I f you haven’t verifiying your ownership before,you have to do this verification process twice.One for your http://yoursite.com and another for http://www.yoursite.com.After that you now can set your preferred domain.

To specify your preferred domain:

  1. On the Webmaster Tools Home page, click the site you want.
  2. Under Site configuration, click Settings.

canonical url

In the Preferred domain section, select the option you want.Then you will see this option,simply choose your preffered domain setting setting preferred domain

Save your setting,and you will receive a message in your dashboard that your preferred domain has been updated.This process ussually only take about 5 minutes or lesssetting canonical url

 

Now your site is done.All the  detected backlinks ,search results and other previous advantage you have gained will still remain and synchronized.So when someone accessing your previous canonical homepage URL for example http://yoursite.com ,will be automatically detected and  redirected to a new preferred domain http://www.yoursite.com

That’s only for Google ,what about other search engine? Let’s get done all by redirecting to the URL you want using .htaccess file .Open your .htaccess file in your root directory.You need to activate the directive like (mod_rewrite engine) to make this work.Note that most of hosting provider have set this by default and they using rewrite module for apache too so you just need to add this couple line to your .htaccess by opening it through your CPanel =>File manager ==> show dot file
If you want www as your standart canonical for your URL then add this :

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.               [NC]
RewriteCond %{HTTP_HOST} ^([^.]+\.[a-z]{2,6})$ [NC]
RewriteRule ^(.*)$       http://www.%1/$1      [R=301,L]

But if you want your standart canonical URL using without www then add this line :

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^yourdomain\.tld$       [NC]
RewriteRule ^(.*)$       http://yourdomain.tld/$1 [R=301,L]

In this case you need to add your domain name and it’s extension eg.COM or NET or ORG and other top level domain name of your own.So if your site is awesomesite.com the line would be

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^awesomesite\.com$       [NC]
RewriteRule ^(.*)$       http://awesomesite.com/$1 [R=301,L

If something goes wrong ,perhaps the rewrite engine was allready on so you just have to remove the first two line of all code above which is RewriteEngine and RewriteBase.After that save the file .That’s it you’re all set up !

give-comment

federal student loan November 13, 2010

Finally, an issue that I am passionate about. I have looked for information of this caliber for the last several hours. Your site is greatly appreciated.

Reply to this

Ron Tedwater November 18, 2010

Really nice post,thank you

Reply to this

Julia March 11, 2011

I have this code previuosly in my .htaccess file

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

and when i add your code below RewriteRule . /index.php [L]

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+\.[a-z]{2,6})$ [NC]
RewriteRule ^(.*)$ http: // www. %1/$1 [R=301,L]

# END WordPress

It creates a redirect loop error..please help

Reply to this

akbar99 March 11, 2011

There are two rewrite rules in that.Try to separate them by making a new line like

#My Preferred domain

the code here

#end my preffered domain

Reply to this

Russell Davison August 31, 2011

To do this in Blogger, you need to go to Settings > Publishing – Advanced Settings – Your Domain and tick the box t0 “Redirect” abcdefg.com to http://www.abcdefg.com.

Reply to this

Leave a Comment

Comment will not appear untill approved.Thanks for waiting.You can use these HTML tags and attributes:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: