Change Your WordPress Domain Name:
The problem. Although it is not recommended, you may want at some point to change your domain name while keeping your blog and its data. Because WordPress records your domain name in the database, you have to change the database in order to connect your new domain name to your WordPress blog.
- You guessed it: the first thing to do is log in to your phpMyAdmin and select your WordPress database.
- Click the “SQL” button to open the SQL command window. In order to change your WordPress URL, execute this first command:
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsite.com', 'http://www.newsite.com') WHERE option_name = 'home' OR option_name = 'siteurl';
- Then, we have to replace the relative URL (guid) of each post. The following command will do that job:
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldsite.com','http://www.newsite.com');
- We’re almost done. The last thing to do is a search and replace in the wp_posts table to make sure that no absolute URL is still here:
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldsite.com', 'http://www.newsite.com');
- You’re done. You should be able to log in to your WordPress dashboard using your new URL.
Explanation. To easily change our WordPress domain name, I took advantage of the super-useful MySQL function “replace,” which allows you to replace one term by another.