Move WordPress site to new domain or new location

If you change the URL or link location of your WordPress site (e.g from www.olddomain.com to www.newdomain.com) or to another directory location (such as from www.domain.com to www.domain.com/blog), there are some steps that should be done to ensure the proper migration.

The tricky part when moving WordPress to another location is that WordPress is using absolute path in URL links instead of relative path in URL link location when storing some parameters in the database. Within blog posts’ contents itself, users may also use the old URLs when creating reference backlinks. All these values in the database will need to be changed when WordPress is moved. The following guide will show you which database fields that has references or values related to blog’s URLs that you want to modify.

NB: this guide is not about how to move WordPress blog from one server or host to another new hosting service.

The first thing to change is to tell WordPress the new location (no changes needed to wp-config.php or .htaccess file). 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.

To update WordPress options with the new location, use the following SQL command:

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';

After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table 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.old-domain.com', 'http://www.new-domain.com');

You will need to re-login to WP Administration as authentication cookie has now became invalid.

Source: www.mydigitallife.info