Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  How-Tos  >  Changing Old URL’s in Website Database After Migration
Top Scroll

Changing Old URL’s in Website Database After Migration

 9 min

If you are planning to move your WordPress website to a new URL and are unsure how to update the old URLs in the database, MilesWeb offers an easy solution with URL hosting and a free migration feature, allowing you to host your website seamlessly. If you’d rather avoid the complicated manual process of updating URLs, this guide will help you.

Introduction

Migrating your WordPress website to a new URL involves more than just changing the website address. Migrating your WordPress website to a new URL involves more than just changing the website address. You must also update the URLs stored in the database, including the different tables in your MySQL database.

For smaller websites, you may manage to update the URLs manually. However, for larger websites with a substantial amount of data, doing this manually becomes impractical. Updating URLs in bulk can be a time-consuming task, and it’s easy to overlook some links during the process.

In such cases, using automated tools to perform mass search-and-replace operations is crucial. This article will guide you through the most efficient ways to update your website’s URL when migrating your WordPress website.

When Should You Update WordPress Website URLs?

There will be several circumstances where updating the URLs in your WordPress website’s database is crucial. 

  • Migrating to a new web server
  • Switching from HTTP to HTTPS
  • Transferring the website to a new domain on the same server
  • Changing the WordPress directory on the existing server

When updating your website’s URL, it is crucial to consider additional factors beyond just modifying the URL in settings. For instance, if your images aren’t hosted on an external CDN, the old URL may still be embedded in the image links within your posts. 

These outdated links can result in broken images or links when visitors view your pages. For smaller websites, you might be able to manually update a few URLs. However, for larger websites or blogs with numerous images, manually changing each URL becomes impractical. In these cases, it’s best to use an automated solution to bulk-replace the URLs in your database.

Ways To Change the Old URLs in Database

Taking a backup of your WordPress database is the first thing you need to do before changing the URLs. If there’s any mistake or anything goes wrong, you

Taking a complete backup of your WordPress database is the first thing you should do before changing the URLs. If there’s any mistake or anything goes wrong, you can take back the changes again.

The database can be backed up manually or with free WordPress plugins. Now let’s learn how to change the URL of a WordPress site.

1. Updating the Website URLs Manually- For small websites

You can manually replace URLs across a small website if you have one. It is a good idea to look for content where you place one link to the home page and the other internal pages and edit them. You can use this method if you have a one-page or small website, as it will avoid the expense of installing plugins.

2. Change the URL in the Database

While changing the URLs, you will face some issues frequently like:

Old URLs in the Widgets and Menus

The old URL exists not just in posts but also in the menus and widgets. Broken Images and Video Links: When you have replaced your website’s URL, there is a chance that your images will not work well. This can even bring issues in the page presentation if you do not change the image URLs.

It stores those URLs in different database tables, so you can always change them manually. If you check the meta value field of the wp post meta table, you get the custom menu URLs in there, and if you check the posts content field within the wp posts table for image URLs. Well, image URLs that older link managers used to come at with came via the link_inage field which happens to be located in the WP-linkfields.

You need to first make sure what to replace. Places where you will be able to find the URL on your website.

  • Inside the posts and pages: “posts_content” field in the “wp_posts” table.
  • Old link manager: “link_url” and “link_image” filed which are present in the “wp_links” table
  • Custom Menu URLs: “meta_value” field present in the “wp_postmeta” table
  • Themes and plugins: “option_value” field in the “wp_options” table
  • URLs present in the comment section: “comment_content” field in the “wp_comments” table
  • You can update the database in the URL by changing the above tables and fields.

3. Using PHPMyAdmin Script for Search and Replace in Database

With MySQL, you can execute raw queries both to find, replace, and use it to update the URL database. This is one of the ideal ways to change the URLs if you have a very big website that needs several changes.

Updating Links with MySQL

You can utilize the MySQL replace command to search and replace the text that is inside the database tables.

To update the URL, you need to run the query given below over different tables and fields.

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find string’, ‘replace string’);

Then, open the PHPMyAdmin panel and go to log in.

Click on the WordPress database

To replace the URL’s across all the database tables, click on the SQL tab and type the code given below:

UPDATE wp_options SET option_value = replace(option_value, ‘Existing URL’, ‘New URL’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;

UPDATE wp_posts SET post_content = replace(post_content, ‘Existing URL’, ‘New URL’);

UPDATE wp_postmeta SET meta_value = replace(meta_value,’Existing URL’,’New URL’);

UPDATE wp_usermeta SET meta_value = replace(meta_value, ‘Existing URL’,’New URL’);

UPDATE wp_links SET link_url = replace(link_url, ‘Existing URL’,’New URL’);

UPDATE wp_comments SET comment_content = replace(comment_content , ‘Existing URL’,’New URL’);

If you are having the images linked to your posts, then you need to also run the additional queries:

If you have images inside the posts:

UPDATE wp_posts SET post_content = replace(post_content, ‘Existing URL’, ‘New URL’);

For images linked in the old manager:

UPDATE wp_links SET link_image = replace(link_image, ‘Existing URL’,’New URL’);

If you have images linked as attachments

UPDATE wp_posts SET guid = replace(guid, ‘Existing URL’,’New URL’);

All the queries given above run for default tables known for having URL entries in WordPress.

Just click on the Go button

The existing URL would be updated to website-wide to a new URL.

Updating the Old URLs in the Database using WordPress Plugins

If you are not able to update the URLs by running the MySQL queries, then you have another option of doing it with the WordPress plugins. These plugins let you update the old URL’s in the database.

Here are some of the plugins which will help you to update the old URL’s in the database:

1. Search and Replace Plugin

The Search and Replace plugin offers an easy-to-use interface within the WordPress Admin dashbord, allowing you to search for and replace text across the entire website. You can either perform a simple search or opt for a “search and replace” action. For instance, to update URLs, just enter the old URL in the search field and the new one in the replace box. You’ll be prompted to confirm whether you want to update both the title and content, then select the relevant posts or pages before clicking Go!

2. Better Search Replace Plugin

Better Search Replace is more than a powerful plugin that lets users alter all the URLs in the WordPress database because it offers you choice by allowing you to replace one database table at a time; this is a much more versatile option for updating.

3. Velvet Blues Update URL

With the Velvet Blues Update URLs you will have a chance to modify URLs all over your WordPress site – for instance, on pages, posts, and much more. Input the old URL and new URL then just select which part of your site should update.

4. WP Migrate

WP Migrate is a WordPress migration plugin which simplifies the exportation process and moving of your website’s database. On migration, find and replace data through the interface of WP Migrate; thus, moving your content and settings to a new location will be much easier.

Updating a WordPress Website’s Domain: A Step-by-Step Guide

Changing the domain of your WordPress site is a significant change that requires much carefulness to prevent broken links, errors, or loss of content. A step-by-step guide will help ensure the update process goes smoothly.

1. Backup Your WordPress Files

First of all, make sure you have a backup copy of your WordPress files before starting with the modifications. You should have a chance to get your website back in case of anything bad happening while modifying your WordPress files. Use tar or zip commands to achieve the backup.

To create a backup using tar:

tar -czvf wordpress_backup.tar.gz /path/to/wordpress/

To create a backup using zip:

zip -arv wordpress_backup.zip /path/to/wordpress/

Make sure to store the backup in a safe location before proceeding further.

2. Check URLs to Replace

Now, try the dry run to find which areas of the old domain must be replaced with the new. It will help you test the changes without implementing them, thus avoiding accidentally changing some URLs in the wrong place.

To execute a dry run, use the following command:

wp search-replace https://webhosting.in/ https://webhostings.com/ --dry-run

Where,
Old URL: https://webhosting.in/ 
New URL: https://webhostings.com/

This will show you the preview of changes to be made, without altering the database. Now take some time to go through the list of occurrences and ensure that everything is okay.

3. Replace the Old Domain with the New Domain

Once you’ve confirmed the results of the dry run and are confident that the replacements are accurate, it’s time to replace the old domain with the new domain.

Run the following command to perform the actual replacement:

wp search-replace https://webhosting.in/ https://webhostings.com/

This command will replace every instance of the old domain (https://webhosting.in/) with the new domain (https://webhostings.com/) across the database.

Conclusion

Website owners often find themselves needing to change the URL of their WordPress website. The process of updating old URLs in the database can be time-consuming and tedious if done manually. For smaller sites or blogs, a simple search and replace may be enough.

However, for a more thorough and reliable solution, especially when dealing with serialized data like images and URLs, it is recommended to use a specialized search and replace tool or plugin. Such tools are useful in website migration or when the URL is changed. We hope this guide has clarified the process for you. If you’re still unsure about updating your WordPress site URLs, don’t hesitate to reach out to experts for assistance.

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.