Update URLs After WordPress Migration

Updated on September 25, 2017

If you are migrating your WordPress site from one domain to another, then you need to update URLs isn’t? Well, changing or updating the domain URLs might seem like a cake walk, but if you don’t do it right way it’s going to cause a hell lot of problems. For example, if you have migrated your WordPress site from domaina.com to domainaaa.com, then you can quickly navigate to WordPress Settings > General and update WordPress Address and Site Address. But if you think that’s the only change you have to do, then you are wrong. What about the URLs that you had added in the Posts & Pages? What about the URLs of images that you had uploaded to the site? Oh! yes, now you know there are plenty of places you need to update URLs, but doing it manually is really a time consuming job & error prone. This tutorial explains how to Update URLs After WordPress Migration.

Well, some articles in the internet says, you can quickly execute few SQL queries to update URLs in posts & pages.

For example, the below queries will allow you to replace all of your old URLs with new URL in all posts and custom fields.

Warning

Remember to take a backup of your WordPress database, before executing the below queries.

UPDATE wp_options SET option_value = REPLACE(option_value, 'http://domaina.com', 'http://domainaaa.com') WHERE option_value NOT LIKE '%{%';
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'http://domaina.com', 'http://domainaaa.com') WHERE meta_value NOT LIKE '%{%';
UPDATE wp_posts SET guid = REPLACE(guid, 'http://domaina.com', 'http://domainaaa.com');

In the above queries, you might have noticed that the character ‘{‘ has been excluded, because that’s part of serialized arrays. For now, you can just execute those queries and read through to know why executing the above queries is just not enough.

What is serialized arrays?

Serialization is now used in many programming languages. For example, have a look at the below example, where one of the resource URL stored as a serialized array.

a:2:{i:0;s:54:"http://domaina.com/wp-content/themes/mytheme/style.css";i:1;s:0:"";}

In the above example, the URL of your theme’s stylesheet is organized in a way that it has data type string and number of characters. It means, it’s a string URL with 54 characters. This is a serialized array and most of the URLs in your WordPress would have been stored this way.

So what’s wrong with serialization?

Nothing wrong, but it just makes data portability little difficult. Imagine that you are updating old domain domaina.com with domainaaa.com, then the above mentioned SQL queries will help you to do that. But do the URLs have same number of characters? domaina.com has 11 characters and domainaaa.com has 13 characters. So if you search and replace domain URLs using SQL queries, you will end up in corrupting the data.

Update URLs After WordPress Migration, the right way!

One thing is for sure, it’s not going to be easy to update serialized arrays. So why not take a help from popular WordPress migration plugins such as WP Migrate DB or All-in-One WP Migration.

Step 1: Download and activate WP Migrate DB Plugin on your old domain (e.g., domaina.com)

Step 2: Go to Tools > Migrate DB

Step 3: Click on Migrate tab

Step 4: The plugin allows you to find & replace texts across WordPress database. You can either choose to export SQL dump file or run a find & replace on the website database directly.

Caution:

If you choose to Find & Replace directly on the site’s database, then do it only if you know what you are doing. As told earlier, take a backup before performing replace operation.

Update URLs After WordPress Migration

Step 5: Click Export button.

Update URLs After WordPress Migration

Step 6: Now go to domainaaa.com and import SQL dump into the WordPress database.

Note:

This tutorial talks about migrating WordPress database ONLY. However, you need to migrate all folders (themes, plugins & uploads) under wp-content to your new domain host.

Was this article helpful?

Related Articles

Leave a Comment