I understand – you want to go the opposite direction and replace relative URLs with absolute ones. Here’s the SQL command to do that:
sqlCopyUPDATE wp_posts
SET post_content = REPLACE(
post_content,
'wp-content/uploads/',
'http://mydomain.com/wp-content/uploads/'
)
WHERE post_content LIKE '%wp-content/uploads/%';
This query:
- Looks for content with relative URLs starting with ‘wp-content/uploads/’
- Replaces them with absolute URLs starting with ‘http://mydomain.com/wp-content/uploads/‘
Just replace “mydomain.com” with your actual domain name before running this query.
If your relative URLs sometimes have a leading slash like “/wp-content/uploads/”, you’ll need to run this additional query:
sqlCopyUPDATE wp_posts
SET post_content = REPLACE(
post_content,
'/wp-content/uploads/',
'http://mydomain.com/wp-content/uploads/'
)
WHERE post_content LIKE '%/wp-content/uploads/%';
As before, I recommend:
- Backing up your database first
- Testing on a development environment before running on production