WordPress – How to Move Blog to New Domain or Location

wordpressIn most cases, the host of a WordPress installation is not the same as the test installation. In the case of testing plugins, themes, and WordPress versions, an exact installation of the original WordPress install would be the best scenario. In other cases, a WordPress installation hosted by an ISP may need to be copied to another ISP. A name change from http://www.olddomain.com to http://www.newdomain.com or http://subdomain.domain.com to http://localhost/subdomain or whatever is possible without breaking the links by using several SQL statements.

Once the blog has been moved (all files copy over in case of moving location or server or new domain name properly propagated across Internet for new domain name), the first thing to change is to tell WordPress the new blog location (wp-config.php should be no changes, and .htaccess file should be also no changes. If for some reason mod_rewrite rules for friendly URLs no longer works, you can always regenerate the .htaccess file via WP Administration’s Update Permalinks page). This value can be changed via WordPress Options page, but if you no longer able to access to old blog URL, you have to modify the value via MySQL database.


The guide uses SQL statements based on MySQL replace() function to modify the database. To run SQL queries, login to MySQL database that stores the WordPress tables via phpMyAdmin or login to the DB server and run MySQL client as root.

Update WordPress options with the new URL values.

UPDATE wp_options SET option_value = replace(option_value, 'http://www.olddomain.com', 'http://www.newdomain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

Update slug posts that are stored in table, wp_posts as guid field. The URL values in this field are stored as absolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:

UPDATE wp_posts SET guid = replace(guid, 'http://www.olddomain.com','http://www.newdomain.com');

If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal links to own blog in all WordPress posts and pages:

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.olddomain.com', 'http://www.newdomain.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.olddomain.com', 'http://www.newdomain.com');

After applying the SQL statement updates, everything should work okay. A re-login to WP Administration may be needed as authentication cookie has now became invalid due to different domain.


Update: I have tested this procedure with successful results. However, I need to note a couple of issues that I encountered in my relatively uncommon installation. A shared database using several installations of WordPress with their unique prefixes. In the above example, the default installation would be wp_options. In my case, I have wp_options, blog2_options, blog3_options, and blog4_options. The SQL statements will need to be applied to each of the options individually. So is true for the wp_posts statement.