Fix Mixed Content on HTTPS websites

What Is Mixed Content?

When you install an SSL Certificate and serve your website over HTTPS, the browser expects every resource on the page — images, JavaScript, CSS, fonts, iframes — to also be loaded over HTTPS.

Mixed Content is the situation where a page is served over HTTPS but some resources still reference URLs beginning with http:// instead of https://. Browsers then display a warning or block those insecure resources entirely.

Simple analogy: You locked the front door (HTTPS) but left a window open (HTTP resource) — the browser can tell your house isn't fully secure yet.

This issue is most common when migrating a website from HTTP to HTTPS, because URLs stored in the database, HTML files, and configuration files still reference http:// from before the migration.

Types of Mixed Content

Browsers divide Mixed Content into two main categories with different risk levels and handling:

TypeResources InvolvedBrowser BehaviorRisk Level
Active Mixed Content JavaScript, CSS, iframes, XHR/Fetch Blocked immediately Very High
Passive Mixed Content Images, audio, video Loaded but shows warning Lower

Active Mixed Content — High Risk

JavaScript or CSS loaded over HTTP can be intercepted and modified by an attacker before reaching the browser (Man-in-the-Middle Attack), potentially delivering malware or stealing user data. Chrome, Firefox, and Safari have blocked Active Mixed Content by default since 2020.

Passive Mixed Content — Lower Risk, Still Problematic

Images served over HTTP cannot directly modify page content, but attackers can substitute fake images or track which pages a user visits. Browsers will load the image but replace the green lock icon in the address bar with a warning indicator.

Problems Caused by Mixed Content

How to Detect Mixed Content

Before fixing Mixed Content, you need to know exactly where it is. Here are the most reliable methods:

1. Chrome DevTools — Most Accurate

  1. Open the page in Chrome.
  2. Press F12 or Ctrl+Shift+I to open DevTools.
  3. Go to the Console tab — look for red or yellow messages starting with "Mixed Content".
  4. Go to the Network tab, reload the page, and filter for requests starting with http://.

Tip: In the Console, type "mixed" in the filter box to see only Mixed Content messages. Each message shows the exact URL causing the issue and the file/line that references it.

2. Online Tools

3. View Source Search

For CMS-based sites, press Ctrl+U in Chrome to view page source, then search for http:// to find any un-upgraded URLs in the rendered HTML.

General Fix Methods

The fix depends on the source of the Mixed Content. Here are the most common cases:

Case 1: URLs You Control (Your Own Files)

Change the URLs in your HTML, CSS, or JS files from http:// to https://, or use protocol-relative URLs:

<!-- Old (wrong) -->
<img src="http://example.com/img/photo.jpg">
<script src="http://example.com/js/main.js"></script>

<!-- Correct -->
<img src="https://example.com/img/photo.jpg">
<script src="https://example.com/js/main.js"></script>

<!-- Protocol-relative (works for both http and https) -->
<img src="//example.com/img/photo.jpg">

Case 2: External Third-Party Resources

If the third-party service supports HTTPS (most do), simply switch the URL to https://. If the service doesn't support HTTPS, download and self-host the file instead.

Case 3: URLs Stored in a Database

For CMS platforms like WordPress that store URLs in a database, you must update the database records — editing PHP files alone won't fix it. See the WordPress section below.

Fixing Mixed Content in WordPress

WordPress stores URLs in its MySQL database, so migrating from HTTP to HTTPS requires a database search-and-replace. Here are the main approaches:

Method 1: Really Simple SSL Plugin (Easiest for Beginners)

  1. Install the Really Simple SSL plugin from WordPress.org.
  2. Activate it and click "Go ahead, activate SSL!"
  3. The plugin will set up HTTP→HTTPS redirects and add necessary headers automatically.
  4. Check the Console again to verify Mixed Content warnings are gone.

Note: Really Simple SSL rewrites URLs at runtime (when PHP generates the HTML) — it does not change the actual database. For a permanent fix, pair it with Better Search Replace.

Method 2: Better Search Replace Plugin (Permanent Database Fix)

  1. Install the Better Search Replace plugin.
  2. Go to Tools → Better Search Replace.
  3. "Search for": http://yourdomain.com
  4. "Replace with": https://yourdomain.com
  5. Select all tables, or at minimum: wp_posts, wp_postmeta, wp_options.
  6. Run a Dry Run first to see how many records will change, then run the actual replacement.

Method 3: WP-CLI (For SSH Users)

wp search-replace 'http://yourdomain.com' 'https://yourdomain.com' --skip-columns=guid

Additional wp-config.php Settings

Add these lines to wp-config.php to enforce HTTPS across the board:

define('FORCE_SSL_ADMIN', true);
define('WP_HOME', 'https://yourdomain.com');
define('WP_SITEURL', 'https://yourdomain.com');

Fixing Mixed Content on DirectAdmin Hosting

AsiaGB Hosting users on DirectAdmin can manage SSL and address Mixed Content issues directly from the control panel:

Step 1: Confirm Your SSL Certificate Is Active

Log in to DirectAdmin → SSL Certificates → verify the certificate status shows Active and the domain matches your site.

Step 2: Add HTTP → HTTPS Redirect in .htaccess

Go to DirectAdmin → File Manager → edit the .htaccess file in your public_html folder and add the code below.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Step 3: Search and Replace URLs in Your Code

Find all HTML, PHP, CSS, and JS files containing http://yourdomain.com and update them to https://.

Step 4: Clear All Caches

Clear your CMS cache, plugin cache, and browser cache before testing. Stale cached pages may still serve old HTTP URLs.

Using CSP Header as a Safety Net

Even after fixing URLs in your code and database, some may slip through. The Content-Security-Policy: upgrade-insecure-requests HTTP header tells the browser to automatically upgrade all HTTP resource requests to HTTPS before loading them.

Add to your .htaccess:

Header always set Content-Security-Policy "upgrade-insecure-requests"

Important: upgrade-insecure-requests tells the browser to try HTTPS first. If the resource genuinely doesn't exist over HTTPS, it still won't load. Use this alongside fixing actual URLs — not as a substitute for doing so.

Bonus: Add HSTS Once Everything Is Clean

After resolving all Mixed Content issues, add HSTS (HTTP Strict Transport Security) to enforce HTTPS for all future visits, reducing redirect overhead and preventing protocol downgrade attacks:

Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"

Preventing Mixed Content in the Future

Frequently Asked Questions

What is Mixed Content?

Mixed Content occurs when a webpage is loaded over HTTPS but some resources — images, scripts, or CSS — are still requested over HTTP. Browsers display warnings or block those resources to protect users.

What is the difference between Active and Passive Mixed Content?

Active Mixed Content (JavaScript, CSS, iframes) is blocked by modern browsers because it can be intercepted and modified by attackers mid-transit. Passive Mixed Content (images, audio, video) is loaded but triggers a warning in the address bar since it poses lower but non-zero risk.

How do I detect Mixed Content on my website?

Open Chrome DevTools (F12), go to the Console tab and look for Mixed Content warnings. You can also use the Network tab filtered to HTTP requests. Online tools like Why No Padlock or JitBit SSL Checker can scan your pages automatically.

How do I fix Mixed Content in WordPress?

Use the Better Search Replace plugin to replace http://yourdomain.com with https://yourdomain.com in the database. Also add define('FORCE_SSL_ADMIN', true) to wp-config.php. The Really Simple SSL plugin can handle this semi-automatically.

What does Content-Security-Policy upgrade-insecure-requests do?

This HTTP header instructs the browser to automatically upgrade any HTTP resource requests to HTTPS before loading them. Add it to .htaccess: Header always set Content-Security-Policy "upgrade-insecure-requests". Use it as a safety net alongside fixing actual URLs in your code.

Does Mixed Content affect SEO?

Yes, indirectly. If Active Mixed Content is blocked, it can break page layout and hurt Core Web Vitals (LCP, CLS). Google uses security signals as a ranking factor, so a page showing "Not Secure" may rank lower than a fully secure equivalent.

Want Hosting with Free SSL — No Setup Required?

AsiaGB Hosting includes a free SSL Certificate installed automatically. DirectAdmin control panel, 99% uptime SLA, and expert support backed by 19 years of experience.

View Hosting Plans