Changing Old URL’s in Website Database After Migration

Posted on

Planning to move your WordPress website to a new URL? Worried about updating all those old URLs in your database? Bluehoster provides an effortless solution with URL hosting and a complimentary migration service, making the transition seamless. If you’d rather skip the complex manual URL updates, this guide is for you.

Introduction

Migrating your WordPress site to a new URL isn’t just about changing the web address. It requires updating the URLs stored within your database, including various MySQL tables.

For smaller websites, manual URL updates might be manageable. However, large websites with extensive data make this approach impractical. Updating URLs in bulk takes time, and crucial links can be easily missed.

Automated search-and-replace tools are essential for these situations. This guide will walk you through efficient methods to update your website’s URL during a WordPress migration.

When Should You Update WordPress Website URLs?

Updating URLs in your WordPress database is necessary in several scenarios:

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

When updating, remember that modifying the URL in settings is not enough. If your images aren’t hosted on a CDN, old URLs might be embedded in your post’s image links.

Outdated links cause broken images or incorrect links for visitors. Small sites might handle manual updates, but large websites or blogs hosting numerous images need automated bulk replacements for all their URLs.

Ways To Change the Old URLs in Database

Backing up your WordPress database should be the very first step before changing any URLs. This gives you something to revert to if an error occurs.

You can backup your database manually or using free WordPress plugins. Now let’s explore ways to change your WordPress site’s URL.

1. Updating the Website URLs Manually- For small websites

Manually replacing URLs works for smaller websites. Carefully search for content where you have internal links to your homepage and other pages and then edit them. This method can eliminate installing plugins. It will come in handy if you have a single-page website.

2. Change the URL in the Database

Common issues to consider when changing URLs:

Old URLs in the Widgets and Menus

The old URL can exist in menus and widgets, not just posts.

Broken Images and Video Links: Your images might be broken. This can affect page presentation.

WordPress database stores URLs in different tables. You can always change them manually. Custom menu URLs are usually found within the meta value field of the wp_postmeta table, and image URLs in the posts content field of the wp_posts table. Older link managers store image URLs in the link_image field within the WP-linkfields.

First, determine what needs replacement and where old URLs are located on your website:

  • Inside posts and pages: the “posts_content” field in the “wp_posts” table.
  • Old link manager: “link_url” and “link_image” fields in the “wp_links” table.
  • Custom Menu URLs: “meta_value” field in the “wp_postmeta” table.
  • Themes and plugins: “option_value” field in the “wp_options” table.
  • URLs within comments: “comment_content” field in the “wp_comments” table.

You can update the database URLs by changing the respective tables and fields.

3. Using PHPMyAdmin Script for Search and Replace in Database

You can use raw MySQL queries to find, replace, and update URLs in your database. This is an effective way to change URLs on large websites requiring multiple changes.

Updating Links with MySQL

The MySQL replace command can search and replace text within database tables.

To update the URL, use this query on the correct table and fields:

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

Open the PHPMyAdmin panel and log in.

Click on your WordPress database.

To replace the URLs across all 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 have images linked to your posts, run these additional queries:

For images inside posts:

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

For images linked with the old manager:

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

For images linked as attachments

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

These queries use default tables known for having URL entries in WordPress.

Click on the Go button.

All existing URLs will now be updated to the new URL.

Updating the Old URLs in the Database using WordPress Plugins

If you have difficulty using MySQL queries to update the URLs, utilize the WordPress plugins. These plugins assist in updating old URLs in the database.

Here are some plugins that can help update old URLs:

1. Search and Replace Plugin

The Search and Replace plugin provides an easy WordPress Admin interface for finding and replacing text across your site. Perform search-only checks or “search and replace” actions. To update URLs, enter the old URL in the search field and the new one in the replace box. You have an option to update the title and content and can pick which posts or pages to update before clicking Go!

2. Better Search Replace Plugin

The Better Search Replace plugin lets you modify all URLs in the WordPress database, and offers a table-by-table replacement option. It provides greater versatility for updates.

3. Velvet Blues Update URL

With Velvet Blues Update URLs you can modify URLs all over your WordPress site on pages, posts, and more. Just add old and new URLs, then select which areas to update.

4. WP Migrate

WP Migrate simplifies exporting and moving your website’s database and offers tools to find and replace data through its interface. This makes migrating content and settings to a new location easier.

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

Changing your WordPress domain is a crucial change requiring careful planning to avoid broken links, errors, or data loss. Here’s a step-by-step guide.

1. Backup Your WordPress Files

Always backup your WordPress files before starting the modification process. Backup your website safely in case of any errors. Use tar or zip commands:

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/

Store the backup in a safe place before proceeding further.

2. Check URLs to Replace

Perform a dry run to determine exactly where within your site the old domain needs to be replaced. The ‘dry run’ command tests changes without implementing them. This helps you avoid unintended URL updates.

To run 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 a preview of changes without altering the database. Review the list to ensure it’s all correct.

3. Replace the Old Domain with the New Domain

Once you have reviewed with the dry run results, remove the old domain with the new one.

Use the command to do the replacement:

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

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

Conclusion

Changing a WordPress URL is quite common to website owners. Manually updating old URLs in the database can be time-consuming. For smaller sites, a simple search and replace might be enough.

However, for reliability, using a specialized tool or plugin for URL replacement is recommended, especially with serialized data such as images and URLs. These tools are extremely helpful for website migration or URL changes in general. If you’re uncomfortable with URL updates, contact a professional for assistance.

Leave a Reply

Your email address will not be published. Required fields are marked *