I recently had to move WordPress blog from my old domain to my new domain (in other words my URL changed). I had a tough time updating all the existing links. Therefore, I decided to document the process in order to make future changes easy and to let other knows how I did it.
Changing the URL of the blog can have several detrimental effects. In my case, I lost traffic on my blog for a while. You also lose ranking on search results. But in my case the change had to be made. Anyway, without further delay, here are the steps:
Step 1: Backup You Databases and Files
Before I do any changes to my databases, I always back them up. On Ubuntu Server, this is what I do to backup my databases:
sudo su cd /var/lib sudo cp -a mysql mysql.bak exit
This will create a backup of all my databases into the folder mysql.bak. In case I screw up this is how I restore the backup:
sudo su cd /var/lib service mysql stop rm -r mysql mv mysql.bak mysql service mysql start
Note the “sudo su” command is needed to gain access to the mysql folder.
Now that the most important step is taken care of, let me proceed to explaining how actually I changed my WordPress blog URL.
Step 2: Install Search and Replace Plugin
The Search and Replace plugin allows you to search for and find strings in your database and replace the strings. You can search in ID, post-content, GUID, titel, excerpt, meta-data, comments, comment-author, comment-e-mail, comment-url, tags/categories and categories-description. It is possible to replace the user-ID in all tables and the user-login for more security in the WordPress-Application.
For convenience, you may use SSH / SFTP to install your plugin. The procedure to enable SSH / SFTP for WordPress is described in this post. After installation, you will find the plugin under “Tools”.
Step 3: Change URLs in WordPress General Settings
Go to WordPress General Settings and change the “WordPress Address (URL)” and “Site Address (URL)” to the domain name or URL you want and save the changes.
Now your WordPress URL/Domain Name should be changed and working. However, we are only half way through. In most cases the post URLs and the links will point to your old domain. Images may also not appear correctly. We will fix these in the next step.