SQL Search & Replace: Rename Existing WordPress Post Image Attachment URLs

In a previous post, I showed us how to move or rename a website to a new domain name / URL without any SEO loss but I missed something important – rename image URLs in existing posts and pages to point to the new domain.

My blog images are stored in an Amazon s3 bucket with URL CNAMEd to s3.w3guy.com.

After changing my blog to a new URL, I needed to rename the image URLs in existing blog posts to my new domain but that would be one hell of a task if I decides to manually edit each posts.

To rename the URL of images attached to WordPress posts, an SQL search and replace will do the job perfectly well.

In my case, I needed to rename the existing post images from s3.w3guy.com to w3guy.com so I used the SQL code below.

[sql]
UPDATE wp_posts SET post_content = REPLACE (
post_content,
‘http://s3.w3guy.com’,
‘https://w3guy.com’);
[/sql]

I hope someone find this useful someday.

Don’t miss out!
Subscribe to My Newsletter
Invalid email address