WordPress Mixed Content After Moving to HTTPS
Clear WordPress mixed content warnings after an HTTPS move: find the http:// URLs left in the database, replace them safely, and force HTTPS in .htaccess.
Your certificate is installed, the site loads over HTTPS, and the padlock still refuses to appear. That is mixed content: the page itself came over HTTPS, but something inside it, such as an image, a stylesheet or a script, is still being requested over plain http://. This walks through finding those URLs, replacing them without corrupting serialized data, correcting siteurl and home, and forcing HTTPS at the server so the problem cannot come back.
TL;DR: Mixed content means part of an HTTPS page is still requesting http:// resources stored from before the move. Fix it in this order: (1) check siteurl/home and any wp-config.php overrides first, and change them through WordPress rather than raw SQL, (2) run a serialization-aware replace, never a raw SQL REPLACE, on the rest of the database, (3) force HTTPS in .htaccess, and (4) if that causes a redirect loop, your TLS is terminating at a proxy or CDN, not at Apache, so change the condition or the CDN’s mode.
What mixed content actually is
Installing a certificate changes how the connection is encrypted. It does not change what your pages ask for. Every http://yoursite.com/wp-content/uploads/logo.png that was written into a post, a widget, or a theme setting before the move is still sitting in the database, and the browser requests it over an insecure connection.
The W3C Mixed Content spec sorts requests into two groups, and the difference matters when you’re deciding how urgent this is:
- Blockable content: scripts, stylesheets, iframes, fetch/XHR, and images that use
srcsetor sit inside<picture>. Blocked outright. This is why a site can look broken after an HTTPS move with no error message anywhere: a stylesheet was silently refused. - Upgradeable content: plain
<img>,<audio>and<video>. The spec says these “should be autoupgraded to a secure transport. If the request cannot be autoupgraded, it will be blocked.” So the browser asks for thehttps://copy instead. If your server has the file over HTTPS, it loads; if not, it’s missing. Firefox has worked this way since version 127, with no fallback to HTTP.
Older guides describe images as passive content that still loads with a downgraded padlock. That matched older browsers, and it no longer describes what a browser following the current spec does.
| Resource type | Examples | Browser behavior (current spec) | Visible symptom |
|---|---|---|---|
| Blockable | <script>, <link rel="stylesheet">, <iframe>, fetch/XHR, <img srcset>, <picture> | Blocked outright, no fallback | Broken layout, missing functionality, missing responsive images, no on-page error |
| Upgradeable | Plain <img>, <audio>, <video> | Requested over https:// instead; blocked if that fails | None if the HTTPS copy exists; a missing image or player if it doesn’t. The console notes the upgrade |
Both are worth fixing. The upgrade only rescues files your own server already serves over HTTPS. An image on an old CDN hostname or a third-party server without HTTPS stays broken.
What WordPress already fixes on its own (5.7 and later)
WordPress 5.7 added a small automatic fix. Reading the WordPress 7.1.4 source (not run), it works like this:
- When the
homeoption changes fromhttp://example.comtohttps://example.comthrough WordPress itself (Settings → General, Site Health, or WP-CLI), WordPress sets anhttps_migration_requiredflag. It skips this on a brand-new site. - While that flag is set, the site uses HTTPS, and
homeandsiteurlshare the same host, WordPress swapshttp://example.comforhttps://example.com(and the escapedhttp:\/\/form) when it outputs post content, excerpts, text widgets and Customizer CSS. - Site Health (Tools → Site Health) shows “Your website does not use HTTPS” with an Update your site to use HTTPS button when your server supports HTTPS. The button changes both addresses for you and puts them back if HTTPS doesn’t work afterwards. If
WP_HOMEorWP_SITEURLis defined inwp-config.php, it tells you to edit that file instead.
Its limits: it only rewrites output, never the stored data. It only covers your own domain, and only those four places. Post meta, theme mods, page builder data and plugin tables are untouched. And the flag is only set when WordPress itself saves the home option, so a raw SQL UPDATE or a WP_HOME constant never switches it on. Treat it as a safety net, then clean the database properly with the steps below.
Step 1: find out what is still insecure
Start in the browser. Open the page, open developer tools, and read the console. Every blocked or upgraded request is named there with its full URL. That tells you what is insecure; it does not tell you where it is stored.
For that, look at the database directly. WP-CLI can count the matches without an export:
wp db search 'http://example.com' --all-tables-with-prefix --stats
--all-tables-with-prefix includes plugin tables that use your table prefix but aren’t registered with WordPress, and --stats prints the number of matches per table. Or export the database and search the dump:
wp db export dump.sql
grep -o "http://example\.com[^\"']*" dump.sql | sort -u | head -50
If WP-CLI is not available, mysqldump produces the same file:
mysqldump -u USER -p DBNAME > dump.sql
Read the unique URLs that come back. Uploads paths point at post content and meta. Theme asset paths usually point at options. Anything with a domain you do not recognise is an external embed, which needs a different fix (covered below).
Step 2: fix siteurl and home first
siteurl and home are the two options WordPress uses to build almost every internal URL it generates. If either still says http://, WordPress will keep emitting insecure URLs no matter how clean the rest of the database is.
Check them:
wp option get siteurl
wp option get home
Change them through WordPress: the WordPress Address and Site Address fields in Settings → General, the Site Health button described above, or WP-CLI:
wp option update home 'https://example.com'
wp option update siteurl 'https://example.com'
These routes run WordPress’s own option hooks, which is what turns on the 5.7 output fix. A direct SQL update also changes the values, and since these two are plain strings, not serialized arrays, it won’t corrupt anything. But it skips those hooks. Keep it for when wp-admin and WP-CLI are both unavailable:
UPDATE wp_options
SET option_value = REPLACE(option_value, 'http://example.com', 'https://example.com')
WHERE option_name IN ('siteurl', 'home');
One trap before you spend time on this. If wp-config.php defines WP_HOME or WP_SITEURL, those constants override the database completely and your update will appear to do nothing:
define( 'WP_HOME', 'https://example.com' );
define( 'WP_SITEURL', 'https://example.com' );
Update them there, or remove them and let the database drive. Check this first; it explains a lot of “I changed it and nothing happened” cases. Our wp-config.php guide covers where these constants sit in the file.

wp-config.php, Settings > General greys out the two address fields, as it did on our test site.Step 3: the replace has to be serialization-safe
Everything else in the database is where the real risk sits, and it is not the risk most people expect. The danger is not that the replace misses URLs. It is that it succeeds at the text level and destroys the surrounding data.
WordPress stores arrays and objects as PHP-serialized strings, and that format records the byte length of every string it contains:
a:1:{s:4:"logo";s:31:"http://example.com/img/logo.png";}
Change http:// to https:// with a raw SQL REPLACE and the text becomes one byte longer while the declared length stays at the old value (s:31 instead of the s:32 the new string actually needs). PHP reads the length, walks that many bytes forward, does not find the terminator where it expects it, and refuses to unserialize the whole array. WordPress then hands the theme or plugin a value that behaves as if the setting was never saved.
We checked the length rule on 2026-11-06 with a small Node script that rebuilds PHP’s serialized-string rule (s:<byte-length>:"<bytes>";) and runs both paths on the example above. It was a re-implementation in Node, not PHP itself. The raw-REPLACE output failed to parse with the mismatch predicted, “declared length 31 but expected terminator ’”;’ was instead ‘g”’”, while the same value with the corrected length (s:32) parsed cleanly back to { logo: "https://example.com/img/logo.png" }. Our serialization-safe search and replace guide goes deeper into how tools handle this.
The symptom in WordPress itself is not an error. It is widgets vanishing, customizer settings resetting, and page builder layouts rendering blank, with nothing in the admin indicating anything went wrong. Recovery from that without a backup is genuinely painful, so take one:
wp db export backup-before-https-replace.sql
Then use a tool that unserializes, replaces inside the decoded structure, and re-serializes with corrected lengths. wp search-replace does this. Dry run first:
wp search-replace 'http://example.com' 'https://example.com' --dry-run --all-tables-with-prefix --skip-columns=guid
Read the report. If a table you do not recognise shows thousands of hits, stop and look before committing. Then run it for real:
wp search-replace 'http://example.com' 'https://example.com' --all-tables-with-prefix --skip-columns=guid --report-changed-only
--all-tables-with-prefix covers every table with your prefix, including plugin tables WordPress doesn’t register. Avoid --all-tables on a shared database: WP-CLI’s docs say it works on “ALL tables in the database, regardless of the prefix”, which includes other sites’ tables. --skip-columns=guid matters too: the guid is a permanent identifier for feed readers, not a live URL, and rewriting it can make subscribers see your entire archive as new posts.
Some builders store URLs in escaped JSON, as http:\/\/example.com. A search for the normal form misses them, so run a second pass on the escaped string:
wp search-replace 'http:\/\/example.com' 'https:\/\/example.com' --all-tables-with-prefix --skip-columns=guid --dry-run
If you need to see which columns are safe for plain SQL and which ones require serialization-aware handling before you run anything, build the statements with the WordPress search and replace SQL tool.
If you cannot use the command line, a search-and-replace or migration plugin that explicitly states it handles serialized data does the same decoding work through the admin screen. Better Search Replace, for example, lists “Serialization support for all tables” and a dry run on its plugin page. If a tool does not say so, assume it does not. Plugins that fix insecure content as pages are served, such as SSL Insecure Content Fixer, are another route; its page also covers HTTPS detection behind a load balancer or reverse proxy. Check what any such plugin changes before you rely on it.
Step 4: force HTTPS at the server
Cleaning the database stops your pages from requesting insecure resources. It does not stop a visitor from arriving on http:// in the first place. That is a server-level redirect. If you can edit the Apache virtual host, Apache’s docs prefer a plain Redirect in the port-80 host:
<VirtualHost *:80>
ServerName example.com
Redirect permanent "/" "https://example.com/"
</VirtualHost>
On shared hosting you only have .htaccess, and there it takes a conditional RewriteRule:
# BEGIN Force HTTPS
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
# END Force HTTPS
Two things about placement. Put this above the # BEGIN WordPress markers, because anything inside them is discarded every time someone opens the Permalinks screen. (If you’re not sure what WordPress’s own default block should contain, or posts started 404ing after an edit here, see the default .htaccess file guide.) And this only works if mod_rewrite is enabled and the virtual host allows overrides (AllowOverride All, or at least FileInfo). On nginx, .htaccess is ignored entirely and this needs to go in a server block instead.
A RedirectMatch in .htaccess will not do this job. It matches on the request path only and has no way to test whether the current request is already secure, so it redirects HTTPS requests back to themselves. The conditional RewriteRule above is the right tool. The htaccess redirect rules guide covers the same conditional pattern for plain URL redirects, and the .htaccess generator tool builds a force-HTTPS block (and others) without hand-editing the file.
Once HTTPS is forced, it’s worth hardening the rest of .htaccess at the same time. See the .htaccess hardening guide for the rules that block direct access to sensitive files and directory listing.
The redirect loop, and why it happens
If the site starts redirecting forever the moment you add that rule, your TLS is terminating somewhere upstream (a load balancer, a reverse proxy, or a CDN), which then forwards plain HTTP to Apache. Apache’s docs explain that %{HTTPS} queries mod_ssl directly, so it “will always report off” when something upstream handles TLS. Apache sees an insecure request, redirects to HTTPS, the proxy forwards HTTP again, and around it goes.
On Cloudflare, check the SSL/TLS mode first. Cloudflare’s docs say that in Flexible mode it “sends unencrypted requests to your origin server over HTTP”, and that “Redirect loops will occur if your origin server automatically redirects all HTTP requests to HTTPS.” Their fix is to set the mode to Full or higher, which needs a certificate on your server, or to remove the origin redirect.
Behind a proxy you control, test the forwarded header instead. This is the form Apache’s own docs give:
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Many guides use RewriteCond %{HTTP:X-Forwarded-Proto} !https instead. That version also fires on any request that has no header at all, including a direct HTTPS request that bypasses the proxy, and that request then loops. We compared the three conditions on 2026-11-16 with Apache 2.4.58, sending plain HTTP requests and setting X-Forwarded-Proto by hand to act as the proxy:
| Condition | No header | X-Forwarded-Proto: https | X-Forwarded-Proto: http |
|---|---|---|---|
%{HTTPS} !=on | 301 | 301 (the loop) | 301 |
%{HTTP:X-Forwarded-Proto} !https | 301 | 200 | 301 |
%{HTTP:X-Forwarded-Proto} =http [NC] | 200 | 200 | 301 |
Be clear about the risk: X-Forwarded-Proto is a request header, and anyone can send it. Apache’s docs say: “Only trust X-Forwarded-Proto if you control the upstream proxy and it overwrites the header on every request. An attacker can forge this header when connecting directly to your server.”
WordPress itself has the same blind spot in that setup. is_ssl() returns true only when $_SERVER['HTTPS'] is on or 1, or, when that isn’t set, when $_SERVER['SERVER_PORT'] is 443. A proxy that forwards plain HTTP to port 80 sets neither, so admin URLs come out as http://, and WordPress’s HTTPS docs warn that FORCE_SSL_ADMIN then loops. Their fix is to read the header in wp-config.php, above the “stop editing” line. This version adds an isset() check so requests without the header don’t raise a PHP warning, and keeps the docs’ strpos() test because “in some setups HTTP_X_FORWARDED_PROTO might contain a comma-separated list e.g. http,https”:
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && false !== strpos( $_SERVER['HTTP_X_FORWARDED_PROTO'], 'https' ) ) {
$_SERVER['HTTPS'] = 'on';
}
The same trust rule applies: only add this when a proxy you control sets the header on every request.
What a database replace will not fix
- Hardcoded URLs in files. Anything written into
functions.php, a child theme template, or an inline asset path is not in the database. Grep the theme directory separately. - Escaped JSON you didn’t search for. If you skipped the escaped second pass in step 3, URLs stored as
http:\/\/example.comare still there. WordPress’s 5.7 output fix only covers them inside post content, excerpts, text widgets and Customizer CSS. - External resources. A third-party script or embed only available over HTTP cannot be fixed from your side. Find an HTTPS version or drop it.
- Caches. Page cache, object cache, and CDN copies keep serving the old markup after a correct replace. Flush all three before concluding the replace failed.
One thing worth skipping: the upgrade-insecure-requests Content Security Policy header will silence the warnings by rewriting insecure requests in the browser. It treats the symptom and leaves the wrong URLs in your database, where the next export, migration, or feed will carry them forward. Fix the data, then use it as a safety net if you want it.
Symptom → cause → fix
The failure modes in this guide produce different symptoms, so this is the fastest way to tell which one you’re looking at before you start changing anything:
| Symptom | Likely cause | Fix |
|---|---|---|
You update siteurl/home and nothing changes | WP_HOME / WP_SITEURL defined in wp-config.php override the database | Update the constants in wp-config.php, or remove them and let the database drive |
| Widgets vanish, customizer settings reset, layouts render blank after a bulk replace | Raw SQL REPLACE broke a serialized value’s declared byte length | Restore from backup, then redo the replace with a serialization-aware tool (wp search-replace or the search and replace SQL tool) |
| Images go missing after the move instead of loading with a warning | The browser upgraded them to https:// and the file isn’t available there, or they use srcset and were blocked | Replace the URLs in the database, and serve the files over HTTPS |
Site redirects forever right after you add the .htaccess rule | TLS terminates at a proxy/CDN that forwards plain HTTP to Apache, so %{HTTPS} never reads on | On Cloudflare, use Full mode or higher; otherwise test X-Forwarded-Proto with =http |
Admin URLs or is_ssl() checks still read http:// behind a working proxy | $_SERVER['HTTPS'] is never set because the proxy, not Apache, terminates TLS | Set $_SERVER['HTTPS'] = 'on' in wp-config.php when X-Forwarded-Proto contains https |
Request path when TLS terminates upstream
Browser (https://)
│
▼
CDN / reverse proxy ── terminates TLS, forwards plain HTTP
│ sets X-Forwarded-Proto: https
▼
Apache ── sees %{HTTPS} = off, redirects to https:// again
│
└── back to the CDN → redirect loop
This is the shape of the loop described above: Apache only ever sees the proxy’s plain-HTTP hop, never the visitor’s original HTTPS request, so a rule that checks %{HTTPS} instead of the forwarded header will fire every single time.
Still stuck?
Re-check siteurl and home after every step, because plugins and migration tools sometimes rewrite them behind you. If the console still names an insecure URL you cannot find in the database, view the page source and search for it there: if it appears in generated markup but not in the database, it is being built in PHP, and the theme or plugin producing it is the thing to fix.
Sources
- W3C: Mixed Content, Upgrade Insecure Requests
- WordPress Advanced Administration: HTTPS, Moving WordPress
- WP-CLI: wp search-replace, wp db search, wp option update
- WordPress Developer Resources: is_ssl()
- WordPress source code: https-migration.php, default-filters.php, class-wp-site-health.php
- Apache HTTP Server 2.4: Redirecting and remapping with mod_rewrite (Forcing HTTPS), mod_rewrite
- Cloudflare: ERR_TOO_MANY_REDIRECTS
William Lopez is the founder of Odie Themes. He builds the free WordPress tools and themes on this site and has been on WordPress.org since December 2019.
FAQ
Questions
Why does my WordPress site still show mixed content warnings after installing an SSL certificate?
The certificate only changes how the connection is encrypted, not what your pages ask for. Old http:// URLs stay stored in the database, inside post content, widget options and theme settings. The browser loads the page over HTTPS, sees an image or script being requested over plain HTTP, and reports mixed content on an otherwise secure page.
How do I find the http:// URLs still in my WordPress database?
Open a page in a browser and read the developer console, which names every insecure request by URL. Then search the database for your domain with the http prefix, using wp db search with --stats or by grepping an exported dump. The hits per table show whether the problem lives in post content, wp_options, or plugin tables.
Can I fix mixed content with a plain SQL search and replace?
Only for scalar values such as siteurl and home, and even those are better changed in Settings > General or with WP-CLI. Many option and meta values are serialized arrays that record the byte length of every string inside. A raw replace changes the text but leaves the old length, so the value fails to unserialize.
What .htaccess rule forces HTTPS in WordPress?
A RewriteRule guarded by a condition on the HTTPS variable, placed above the BEGIN WordPress markers so that WordPress does not wipe it. Behind a proxy or CDN the HTTPS variable reads as off even on secure requests, so test the X-Forwarded-Proto header with =http instead, and only if your proxy always sets it.
Why did my site go into a redirect loop after forcing HTTPS?
Your TLS is almost certainly terminating at a proxy or CDN that forwards plain HTTP to Apache. The rewrite sees an insecure request, redirects to HTTPS, the proxy forwards HTTP again, and the loop repeats. On Cloudflare, Flexible mode causes exactly this. Use a full-TLS mode, or test X-Forwarded-Proto and set the HTTPS server variable in wp-config.php.
Does mixed content break the whole page or just the padlock?
It depends on the resource. Scripts, stylesheets, iframes and fetch requests over http:// are blocked outright, which can break layout or functions with no visible explanation. Under the current W3C spec, browsers retry plain images, audio and video over https and block them if that fails. Images using srcset or picture are blocked. Both kinds are worth fixing.