After migrating a site to a new server, i discovered image links within the post where broken. I never had the chance to change the links before exporting the database because the site had already been taken down. I only had access to the .sql file backup and files.
The Problem
I spent some time investigating the links and discovered the links in the Media Library where correct however, for some reason after the migration to the new host, the image links within the post content had all been changed and a 1 had been added to all image links like this:
Before Migration
image1.png
After Migration
image11.png
So how do you fix this problem without accessing phpMyAdmin and using a SQL query to search and replace all links?
The Fix
Within your WordPress installation, you can install a plugin named Search & Replace.
This plugin enables you to do a SQL query from within your WordPress admin screen without using phpMyAdmin.
Step 1 – Once installed, go to Tools > Search & Replace > Backup Database and create a SQL file which you can download locally to your desktop.
Step 2 – Under the Search & Replace tab, type in what you are searching for in the Search for: field which in my case was 11.png.
Step 3 – Then type what you want to replace it with in the Replace with: field which in my case was 1.png
Step 4 – Select the tables you want to access to make changes in which in my case was all tables however i could have selected only the tables which store the post posts content.
Step 5 – Select Dry Run so you can compare the broken links to the changes that the plugin will make afterwards and click the Search and Replace button.
This gives you the chance to inspect the broken links and see what they’ll be changed to before making permanent changes to your database.
Once you are happy with what you see, then you can deselect Dry Run and click the button again to make the changes.
Here’s what the plugin settings, discussed above, look like:
Don’t forget to backup your database beforehand & do a Dry Run first!
Other Options i Tried
I did try the Velvet Blues plugin however, as you can see in the Velvet Blues plugin screenshots, it doesn’t enable you to search for & replace specific numbers and characters added to your image filenames within the post content only, before the file extension like the Search & Replace plugin does.
Was This Tutorial Helpful?