You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WordPress切换HTTPS后图片仍为HTTP引发混合内容问题的解决方法

Hey there, let's tackle that mixed content error you're seeing after switching your WordPress site to HTTPS. Those HTTP image URLs are causing the browser to throw warnings, but we've got several solid ways to fix this:

1. First, Make Sure Your Site URLs Are Set to HTTPS

Before diving into image fixes, double-check your core WordPress settings—this is the foundation:

  • Head to Settings > General in your WordPress dashboard.
  • Update both WordPress Address (URL) and Site Address (URL) from http://yourdomain.com to https://yourdomain.com.
  • Hit "Save Changes" and you're good to go here.
2. Bulk Replace HTTP Image URLs in the Database

Most of your old images are referenced in post content and metadata with HTTP. Here are two ways to update them en masse:

Option A: Use a Plugin (No-Code, Safe for Beginners)

Plugins like Better Search Replace or Velvet Blues Update URLs are made for this exact task:

  1. Install and activate your chosen plugin from the WordPress plugin repository.
  2. For Better Search Replace:
    • In the plugin's settings, enter http://yourdomain.com in the "Search for" field, and https://yourdomain.com in "Replace with".
    • Select all database tables (or at least wp_posts, wp_postmeta, and wp_options—adjust the wp_ prefix if your site uses a different one).
    • Start with a "dry run" to preview changes without modifying anything. If the preview looks correct, uncheck the dry run box and run the replacement.

Option B: Run SQL Queries (Advanced Users)

If you're comfortable with database tools, use phpMyAdmin to run these queries (always back up your database first!):

  1. Log into your hosting control panel and open phpMyAdmin.
  2. Select your WordPress database.
  3. Go to the "SQL" tab and execute these commands one by one (replace yourdomain.com and wp_ as needed):
    UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://yourdomain.com', 'https://yourdomain.com');
    UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'http://yourdomain.com', 'https://yourdomain.com');
    UPDATE wp_options SET option_value = REPLACE(option_value, 'http://yourdomain.com', 'https://yourdomain.com') WHERE option_name IN ('home', 'siteurl');
    
3. Refresh Your Media Library & Thumbnails

Sometimes thumbnail URLs might not update automatically. Fix this with a thumbnail regeneration plugin:

  • Install and activate Regenerate Thumbnails.
  • Go to Tools > Regenerate Thumbnails and click "Regenerate All Thumbnails". This will update every image size to use HTTPS.

To prevent future mixed content issues, add a rule to your .htaccess file to redirect all HTTP requests to HTTPS:

  1. Access your site's root folder via FTP or your hosting file manager.
  2. Edit the .htaccess file and add these lines at the top:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    </IfModule>
    
    Alternatively, use the Really Simple SSL plugin—it automates this setup and helps detect remaining mixed content.
5. Check for Hardcoded URLs in Themes/Plugins

Occasionally, themes or plugins might have hardcoded HTTP image URLs. Here's how to fix that:

  • Use the Theme Editor under Appearance (or FTP) to search your theme files for http://yourdomain.com—replace any matches with https://.
  • Do the same for plugins: check their files for hardcoded URLs. If you find any, update the plugin first (if it's outdated), or modify the code (make a backup before editing!).

After completing these steps, clear your browser cache and any WordPress caching plugins you use. Then, open your site in Chrome (hit F12 to open DevTools) and check the Console tab for any remaining mixed content errors—they should be gone!

内容的提问来源于stack exchange,提问作者Daniel Washington Ignacio

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 09:47:56