2

I migrated my WordPress site to a new host and new URL. I've done all the typical search and replace in mysql and the site works great.

However, the links of my images are all missing .co.uk, thus not working.

Image below

The odd thing is, all the image URLs are correct in the source code of blogs. But in my media library, they are all missing .co.uk.

How do I add .co.uk back into my media library URLs?

  • 1
    Search and replace doesn't usually work on everything in WP because some of the data is serialized. Look for a "database migration plugin" - there are several that work well - that will find all the old URLs and replace even the serialized copies, like media library URLs. – WebElaine Jun 12 '17 at 15:40
  • 1
    Let me guess... You replaced domain.com with cosworth-europe.co.uk right? That will replace the string without updating the serialized data. You should use a plugin such as Better Search Replace if you want to replace serialized data. – Jack Johansson Jun 12 '17 at 16:44
5

As mentioned in the comments under your question, some data in the WordPress database is serialized and therefore not possible to change with a simple find and replace.

You should read through the Moving WordPress section of the codex. Specifically the Changing Your Domain Name and URLs portion. I usually use a plugin or a command line tool depending on what's available to me.

Plugin:

Better Search Replace is a useful plugin recommended in the entry above. There are other plugins that will do the same things but this is my preference. Some features that I enjoy are:

  • Support for serialized data.
  • The ability to select single or multiple tables.
  • A "dry run" feature to test and verify your changes before actually performing them.
  • Very few server requirements (all you need is a WP instance.)

CLI Tool:

Another option that handles serialized data is the WP-CLI's search-replace tool. This option is used from the command line via something like SSH and requires the wp-cli to be installed on the server. You can take a look at the docs for all available options and examples but the basic usage is:

# Search for old domain name and replace it with a new one
$ wp search-replace 'http://old.example.dev' 'http://new.example.com'
| improve this answer | |
  • 1
    If you feel this answer should be down voted could you please leave a comment here explaining why so I can update or remove it. I think this answer is valid but I'm open to criticism. Thanks! :-) – DaveLak Jun 12 '17 at 17:57
  • 1
    Why this was down voted is beyond me. I upvoted it. Better Search and Replace is great for serialized data such as widgets, custom meta boxes, and this situation. – Christina Jun 12 '17 at 19:35
  • 1
    Thanks Christina , I think the down vote was due to the plugin recommendation being the only suggestion. That is understandable, I generally dislike answers that only recommend plugins however I felt in this case it was justified. Either way, I updated my answer to include a reference to the Codex article that suggestes it. Hope it helps someone! – DaveLak Jun 12 '17 at 23:10
  • Better Search Replace is a great plugin and I use it all the time. It may have been a downvote because in order for BSR to replace the Media URL, you need to check "Replace GUIDs" which isn't checked by default. It wasn't working for me until I looked at the table and saw the URL is stored in the GUID field. – Jared Pomranky Jun 19 '19 at 18:38
1

This is a pretty common problem, so I think it deserves a thorough answer that covers the situation most are probably Googling when they find this.

For Montrealist's Specific Issue

For the specific question, it looks like @montrealist improperly ran a database find/replace process at some point. I see the URL for the media is:

http://www.cosworth-europe/sam/wp-content/...

I'm guessing that this should be:

http://www.cosworth-europe.co.uk/sam/wp-content/...

At some point, you lost the host TLD, so that's the first thing that would be worth looking at here. You could re-run a find and replace with something like this:

  • Find: //www.cosworth-europe/
  • Replace: //www.cosworth-europe.co.uk/

This should correct the specific issue I see here, assuming that my assumptions are correct here.

For Those Googling Similar Issues

WordPress stores many references to URL's inside of its database. There's no single source config for a site's host, so you'll need to run a database find and replace the process to fix this. Depending on where those images are used, you may need to make sure that serialized strings are properly replaced as well.

For most cases, I'd recommend this as the best fix:

  1. Install the Better Search Replace plugin
  2. Find and replace your domain excluding the protocol, so find //www.olddomain.com with //www.newdomain.com
  3. Test and confirm that there are no issues, then uninstall and remove the plugin

I don't typically recommend plugins as solutions, I code most everything minimally myself but for this specific case, I'd personally use the WP Migrate DB Pro plugin for this and other database related transfers. The Better Search and Replace plugin is developed by the same company, Delicious Brains, and it provides the exact same find and replace process. It's a great option for thoroughly solving this problem.

If you do encounter issues, and you're unable to login to WordPress you can (S)FTP into your installs directory and set or update the following constants in your wp-config.php file:

define( 'WP_HOME', 'https://www.example.com' );
define( 'WP_SITEURL', 'https://www.example.com' );

This should only be done temporarily though, once you correct the issue in the database it's best to remove this from your wp-config.php file afterward.

Changing The Site URL

| improve this answer | |
0

My 'home' option_name in wp_options table was missing the .co.uk. Silly mistake! Next time, I'll try the migration plugins you helped out with.

| improve this answer | |
0

Came to look this up - try this plugin as well as Velvet Blues Update URL - neither worked. Then I realized, why on earth am I not just updating this via MySQL?

First, update your wp_posts table. Then your SQL looks like this:

    UPDATE `wp_posts` SET post_content = REPLACE(post_content, 'oldurl', 'newurl') WHERE post_content like "%oldurl%"
| improve this answer | |
0

You should use WP all in one migration plugin to migrate the website. https://wordpress.org/plugins/all-in-one-wp-migration/

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.