So, you’ve launched your WordPress site on a non-www domain, like example.com, but since then found out that running it on on www, like www.example.com, is better and want to move? You’re in luck, because it is really easy.
Oh, if you haven’t figured out why www is better yet, check out my post “To www or not to www – Should you use www or not in your domain?”
Moving from non-www to www: Step by step
Read through these steps, before you follow them closely, step by step. Don’t miss a single one of them, and you’ll be perfectly fine – both for now and in the future.
Step 1: Disable current redirects
If you have setup any redirects from www to non-www, disable them now. Don’t setup redirects in the other directions just yet. Let’s have your website work on both domains during the transition.
Step 2: Backup your database
Next, backup your database. Yes. Do it. Now. If you don’t know how, install WP-CLI (if you haven’t already) and run this command:
$ wp db export --add-drop-table
Step 3: Analyze your database
Take a look at your database. See what’s in the values in the *_options table, the values in all the fields in the *_posts table and in the value field in the *_postmeta table. Maybe you even have some values in other *meta tables too?
Step 4: Realize you’ll mess this up
Sometimes a simple UPDATE SQL statement with the REPLACE() function on each of those fields will do. At other times, that will corrupt your data since some of those fields contains serialized data. It is your job to look through them and fix them accordingly. One little mistake here and you can mess things up really bad. You might even mess up things that you won’t discover until you’ve finished a backup rotation cycle or done so many other changes that you can’t easily merge the data.
Step 5: Do it with WP-CLI instead
Now, instead of doing anything with that database, install WP-CLI (if you haven’t already) and run this command:
$ wp search-replace 'https://example.com' 'https://www.example.com'
If you somehow messed up your database, revert the effups by running:
$ wp db import
Step 6: Fund WP-CLI
Now, consider how much time and hassle WP-CLI has saved you, and go support the development of WP-CLI financially. Value both the time saved from replacing values in the databse, the comfort of knowing that a professional did this for you, the delightful feeling of knowing you did not screw the site up and the relief of the stressful you never got into.
Step 7: Setup redirections
Finally, setup redirections from your non-www domain to your www domain. Here is how to setup redirections in Nginx.
Will this affect your SEO?
From an SEO perspective, using www or not does not affect your SEO at at all. Transitioning from one domain to another will usually give you a temporary setback. Transitioning between www and non-www: I don’t know. I’m guessing not. I you do know for sure, please leave a comment.
Thank you Bjørn Johansen!
What’s up, for all time i used to check weblog
posts here in the early hours in the morning, because i enjoy to learn more and more.
thanks for this article
Thanks for this. I am having the issue on my blog. Two separate URLs for posts. One for https:// and the other http://www
Redirection plugin fixed only the homepage.
Why dont you use www in your own web ?
I did switch for a while, but then learned the lesson that whatever you have: Don’t switch.
Thank you very much. I have successfully moved by blog (www.latestjambnews.com) to www. today.
I have the opposite problem…. would like to change my www. to the non www version as I found google now see my seo as two seperate entities in SEO terms and offers be analytics for both. I rank much higher for non www but in my new site made it a www. which was a mistake. Do I just do the same approach as above?
Comments are closed.