Migrating WordPress blog to another domain


Recently I had to migrate a blog from a subdomain to a brand new domain. Hereby some notes as this was not as straightforward as I have initially thought.

WARNING: use this guide to your own risk without any guarantees. Always make sure you have a backup of all your data before performing any migrations.


The problem

A WordPress-based blog should have been moved from a subdomain, e.g. “blog.myoldsite.com” to a new domain, e.g. “mynewsite.com”.


You have a new domain where to move to. You have shell access to the hosting server(s).

You have login and password to your WordPress database ready.

How to solve

New hosting location

Make a backup from the old WordPress installation. Login to the host where your new site is going to be hosted on. Copy the WordPress installation to the new location (if applicable). Make sure the new folder and all sub-folders are NOT writeable by anybody except for the user (so not by group/other users).

Prepare for the database fixes

This was one of non-apparent things, but the old URLs are apparently stored in many placed in WordPress database. This needs to be fixed, otherwise the links will not be working. One way is to use the Database search and replace script which helps to replace the old URLs with the new ones across the entire database.

Download a copy of the script to the new location under e.g. the root folder or to a location that is accessible directly from a URL e.g. mynewsite.com/script-name. Note that it shall be NOT put under the e.g. wordpress folder as the URLs will be handled by WordPress.

Point URL to new domain

You start with the old domain, going to your WordPress Administration, e.g. blog.myoldsite.com/wp-admin, and then open Settings | General page and change “WordPress Address (URL)” and “WordPress Address (URL)” if necessary (see WordPress documentation for the difference) to point to the new URL, e.g. “mynewsite.com”. Note that after this your old URL becomes unusable for a while, but this will be fixed in a few steps.

Fix database

Now many things are still broken, but fortunately they can be fixed. Point browser to the URL corresponding to the database script above. Enter the database credentials and put he old url “blog.myoldsite.com” to the search field and the new URL, e.g. “mynewsite.com” to the replace field. You can perform dry run to check what is going to be done and then the actual run to finalize the change. When finished all broken links shall be functioning. Well… almost…

Fix WordPress theme

Apparently WordPress theme may still have problems. Go to Settings | Permalinks in WordPress administration panel, e.g. mynewsite.com/wp-admin and change the permalink setting temporary to another setting, save and then put it back. This will ‘kick’ WordPress to reset the permalink settings to correct setting again. Don’t ask why, this should not be necessary, but apparently is still needed.

Another point is to go to Themes | Theme Options | Show information on sidebar and check the correct widgets are shown. They may be pretty messed up after migration (or after theme change), this part has to be done manually. Also check image and menu as it may be messed up (e.g. including ALL pages instead of the selected ones).

Final checks

Finally browse to your new site and check everything is shown correctly and the links can be properly followed.

Good luck with your migrations!