How to stop Google indexing both www. and no-www versions of my website

First, I hope you put a proper 301 redirect for any page in your htaccess.

If some of your pages require parameters, like example.com/?p=20, then you need to use mod_rewrite with [R=301] instead of the easier mod_alias Redirect directive in your htaccess. Also, until Google Bot comes again and indexes, it will not update the Google index.

Second, it will take some time for Google to reindex your website. You can try and submit a proper sitemap (sitemap.xml) to google via Google Webmaster Tools but it still might take some time.

Third, you might want to use a rel=canonical tag on your pages - especially if your redirect is not working yet to hint Google for proper indexing of your pages.


In addition to Evgeny's very good points, it should be noted that the Google Webmaster's tool allows you to specify a preferred domain, either with or without the www prefixes. Google's explanation of this option follows:

The preferred domain is the one that you would like used to index your site's pages. If you specify your preferred domain as http://www.example.com and we find a link to your site that is formatted as http://example.com , we'll treat that link as if it was http://www.example.com . In addition, we'll take your preference into account when displaying URLs in our search results. It may take some time for changes to be reflected in our index.

You'll find the option under "Site Configurations\Settings".