Changing URL When Migrating WordPress Site

Changing URL When Migrating WordPress Site

Changing URL When Migrating WordPress Site

Time To Start Fresh:

During a recent WordPress migration/restoral I ran into an issue that many before me have. That is that my restored WordPress database was still pointing its URL’s to the old WordPress site. With the URL’s redirecting to the old site I was unable to log into the back-end or edit anything on the newly restored site. This guide will show you how I went about correcting this issue.

Environment Situation:

  • I am migrating an old WordPress site to a new WordPress site, with a different URL
  • I have a duplicated copy of my WordPress installation directory from the previous site (old-website.com)
  • I have a complete SQL backup of my previous database (OLD-DATABASE)
  • I have brand new WordPress installation under a different URL (new-website.com)
  • I have a brand new SQL database with no data in it (NEW-DATABASE)

Lets Begin:

Start by making sure you have a backup everything such as: Both new and old WordPress root directories and both new and old databases. This will help you out in the long run if you accidentally break anything during this database edit. Once you have your backups, you will want to copy the entire contents of your old WordPress root directory into the new WordPress root directory, making sure to overwrite everything. Depending on your site this could take some time to do so be patient.Once you copy over your old site’s root directory into your new site’s root directory we can move on to editing the database.

 
In my situation my hosting provider only gives me access to phpmyadmin so that is what I will be using for this guide.
 
1.    Import your old WordPress database into your new WordPress database.
2.    Next you will need to click on the SQL table tab and you should get a window like the one below
celeriummind-wordpress-migration-phpmyadmin
celeriummind-wordpress-migration-phpmyadmin-2
3.     Run the following SQL queries changing site url’s with your old and new url’s. Please note that WP_OPTIONS, WP_POSTS, and WP_POSTMETA may appear different in your database. Just view the tables for your database using phpmyadmin and look for tables with similar wording.
 
Example: NJUewHQDposts = WP_POSTS. This all just depends on your hosting provider and how they name them.
 
UPDATE WP_options SET option_value = replace(option_value, 'http://old url.com', 'http://new url.com') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://old url.com','http://new url.com');

UPDATE wp_posts SET post_content = replace(post_content, 'http://old url.com', 'http://new url.com');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://old url.com','http://new url.com');

celeriummind-wordpress-migration-phpmyadmin-3

4.     Now you will need to edit your wp-config.php file which will be in your root directory. You will need to change databasename, username,password, and host:

/** MySQL database name */
define('DB_NAME', 'databasename'); 

/** MySQL database username */ 
define('DB_USER', 'username-here');

 /** MySQL database password */ 
define('DB_PASSWORD', 'password-here'); 

/** MySQL hostname */ 
define('DB_HOST', 'localhost-here'); 

You should now be able to browser to your new WordPress site without it redirecting you to your old url’s. If you still are experience issues I would suggest clearing your browser history and cookies and reloading your site. In my experience I had a few issues with some pages still redirecting to the old urls, but I fixed that by editing the page and re-saving it, which updated the url.

Conclusion:

Now please don’t expect this to be a 100% fix, especially if you had a lot of customization’s before. This guide is more there to help you through the migration give you the ability to

References:


celeriummind-logo