Changing domains with WordPress doesn’t have to be a headache. You might think that simply updating your wp_options table in the database might be enough… or that perhaps you could do it in… you know, the wp-config file? Well, you would be part right. Changing your database values for ‘home’ and ‘siteurl’ are key to getting your site to work on a new domain… but before you mark this task is done, you might want to make sure your images will work once you switch off (if you intend to) the old domain. See with each post image (images are saved as posts in the database) there is a GUID stored. This has an absolute path to where the image resides and doesn’t rely upon your database settings. So if you up and move your site off to another domain, you are going to want to update this as well.
Before we do anything, you have made a copy of your database, riiiiight? Good.
You will want to get into PHPMyAdmin and run the following SQL:
UPDATE wp_posts SET guid = REPLACE ( guid, 'http://exampleoldsiteurl.com', 'http://examplenewsiteurl.com');
Of course this assumes you have used the default table name and you replace the URLs in the query with your actual domain names.
Now, this gets you a good bit of the way there… but you are STILL going to have bad paths if you kill off your old domain… this is because in your actual post content you are referencing absolute paths to your old domain. Well depending on the scope of your site you can either edit each post/page manually… or do a find/replace in your database. This would be best done before you import your database onto the new server.
So if we rewind a bit, you should have 1. backed up your database and 2. imported into your new site and 3. updated your settings.
To make things a bit easier for you on the migration, stop after you do your export… open up your SQL in a text editor and do a find/replace for your old URL and replace it with the new one. Now that your SQL is clean, you should be able to do an import into the new database and all your links will work fine. Since you are doing a replacement of all of your data, there shouldn’t be a need to follow up with the query above.
For more information check on the WordPress Codex page about migrating your site.