Mirror site as the definitive version?

Migrations are really tricky because they could be really easy or a pain in the ass. (If you want a fast solution just skip the explanation and go to the Fast solution).

The easy part

When you are migrating your website you will need to use MySQL and access to your PHPMyAdmin.

Once you login to your PHPMyAdmin you need to find your new database with the old.com urls and click the “SQL” tab.

There you will paste this SQL:

  UPDATE wp_options
  SET option_value = replace(option_value, 'http://old.com', 'http://new.com')
  WHERE option_name="home"
  OR option_name="siteurl";

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

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

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

Heads up! Remember to change every old.com with yourOldUrl.domain and every new.com with yourNewUrl.domain.
Ex. old = testing.com | new = production.com

To really fast walk you through this code, you have to know that there are three tables where we have stored our urls on a normal/easy migration: wp_options,wp_posts,wp_postmeta; and this code simply replace one string to another.

What could possibly go wrong?

If you have a custom theme or plugins that stores data in different tables (normally wp_options) and if they store serialized data (and they do!), that would be a real pain in the ass because serialized data is an array stored as an string and if you change any text’s length (old.url = 7 characters vs mynew.url = 9 characters) It will cause an error and won’t recognise the string as a serialized string anymore.

Read more about serialize data here.

Fast Solution

I always migrate every project from it’s testing environment to the production server so I made this library to make my life easier.

It will help you to migrate urls from one server to another in just one click.

Hope this helps.