星期五 , 28 2 月 2025

SQL替换

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:

  1. Looks for content with relative URLs starting with ‘wp-content/uploads/’
  2. 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:

  1. Backing up your database first
  2. Testing on a development environment before running on production

Check Also

VSCODE 扩展

Here are some o …

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注