Migrating WordPress site from staging to production ? or changing the domain of your WordPress site ? You migrated files and database, configured wp-config.php but while browsing new domain (production site ) you are redirected to old domain (staging site) ?

This a common problem faced by people who are not familiar with WordPress site migrating process. WordPress migration is not simple as migrating OpenCart or other where you migrate files and database and update the config file and it works in WordPress you will need to manually update the link from database or you can use some migration plugins like WP SYNC DB, DUPLICATOR etc..

But in this post we are going to discuss on how to update the database manually for WorPress Migration to work.

Open you database from phpMyAdmin or in command line and execute the following Queries. Do not forget to change ‘http://oldsite.com’ and ‘http://newsite.com’ to the URL you are migrating and migrating from and the database prefix that you have used for your WordPress site. Here the database prefix is ‘wp’ change it to your database prefix.

 SET @oldsite='http://oldsite.com';
 SET @newsite='http://newsite.com';
 UPDATE wp_options SET option_value = replace(option_value, @oldsite, @newsite) WHERE option_name = 'home' OR option_name = 'siteurl';
 UPDATE wp_posts SET post_content = replace(post_content, @oldsite, @newsite);
 UPDATE wp_links SET link_url = replace(link_url, @oldsite, @newsite);
 UPDATE wp_postmeta SET meta_value = replace(meta_value, @oldsite, @newsite);

/* only uncomment next line if you want all your current posts to post to RSS again as new */
 #UPDATE wp_posts SET guid = replace(guid, @oldsite, @newsite);

Once you execute it successfully, check if the migration is now working or not. If its working there might be something that you will need to do extra ‘Updating Permalink’ if you are getting 404 not found error in other pages than homepage. Login to your admin dashboard and update Permalink and your migration will work like charm. Good Luck with your WordPress migration. 🙂