This article assumes your site is hosted on a Apache webserver.
When you first set up a WordPress site, you can decide if you want to use the www version of the domain or the non-www version of the domain. Personally I prefer the www version, but you can make your own decision. Either way, the decision you made will be shown in the admin dashboard on your site.
- Am I WWW or Non-WWW Right Now?
Go to your WordPress admin dashboard and click through to Settings and then General. Next take a look at what you have for your WordPress Address (URL) value. Whatever you set up there when you created your site is what your choice was for your domain. For example this is what mine looks like on my site.
If you have a brand new site you can decide what to put into this box, but if your site is established I would not change the value in this box unless you know what you are doing. This means that whatever is in there should be your preferred version of your domain. In my case this is the www version.
- Google Webmaster Tools
- Go to Google Webmaster Tools and set-up your preferred domain. This will help the search engines (well the Google search engine at least) to understand which domain version you want to use.
- Browser Test
Go to a browser and type in the www version of your site and watch what happens. Next type in the non-www version of your site. You are checking to see if your site automatically redirects to your preferred domain version when you address it using the wrong version of your domain (the one not specified on the WordPress dashboard under settings/general).
If it doesn’t then you need to put some lines of code into the .htaccess file to make the server perform the redirect for you whenever someone tries to refer to your domain using the “wrong” version.
- Edit Your .htaccess File
If you are not confident doing this you can ask your host to help you. It is the sort of thing they are usually happy to do.
Preferred Domain is WWW Version?
If your WordPress Settings/General dashboard setting is : www.yourdomain.com then these are the lines to place in your .htaccess file. You must of course replace yourdomain.com with whatever your domain is on both lines.
Preferred Domain is non-WWW Version?
If your WordPress Settings/General dashboard setting is : yourdomain.com then these are the lines to place in your .htacess file. You must of course replace yourdomain.com with whatever your domain is on both lines.
- What Next?
The changes you made to your .htaccess file will immediately start working and if you perform the test in step 3 again you should see a different outcome.
However, you will have to wait a while for the Google index to be rid of any pages using the wrong version of your domain. This will eventually clear as from now on, even though people may still link to and access your site using the wrong version, as your server will be correcting the outcome at source and as Google is aware of which domain you prefer, the two things will eventually mean your indexing is cleaned up.
This is because despite what you tell Google is your preferred domain, if your site is reachable using any version of a URL Google will try to index it. If you set your .htacess file up to intercept this at the server level, then this fact is never revealed to Google and do it won’t try to index the alternate version of your URL.