How7o
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Reading: Fix ERR_TOO_MANY_REDIRECTS in WordPress After Switching to HTTPS
Share
How7oHow7o
Font ResizerAa
  • OS
Search
  • Home
  • Tools
  • Prank Screens
  • Learn
  • Blog
  • Contact
Follow US
© 2024–2026 How7o. All rights reserved.
How7o > Free Laravel, PHP, WordPress & Server Tutorials > Web Development > Fix ERR_TOO_MANY_REDIRECTS in WordPress After Switching to HTTPS
Web Development

Fix ERR_TOO_MANY_REDIRECTS in WordPress After Switching to HTTPS

how7o
By how7o
Last updated: May 10, 2026
7 Min Read
WordPress too many redirects HTTPS — Cloudflare flexible SSL loop and the wp-config fix
SHARE

A wordpress too many redirects https loop right after switching to Cloudflare’s free SSL is almost always the same bug: Cloudflare is in Flexible SSL mode, serving visitors HTTPS while fetching your origin over HTTP. WordPress sees the plain-HTTP request, notices the Site URL is https://, and redirects back to HTTPS — which Cloudflare forwards as HTTP, and the loop is on. Add two lines to wp-config.php to make WordPress respect Cloudflare’s terminated-TLS signal and the loop stops.

Contents
  • TL;DR
  • Why the loop starts
  • Quick fix — tell WordPress to trust the forwarded-proto header
  • Blunter alternative — unconditional HTTPS=on
  • The proper long-term fix
  • Frequently asked questions
  • Related guides
  • References

Last verified: 2026-04-23 on WordPress 6.5 with Cloudflare SSL and on a generic nginx reverse proxy. Originally published 2023-02-07, rewritten and updated 2026-04-23.

TL;DR

// wp-config.php — above the "stop editing" line
if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] ) {
    $_SERVER['HTTPS'] = 'on';
}

Why the loop starts

Cloudflare’s Flexible SSL mode sits in front of your origin and does TLS termination:

  1. Visitor → https://example.com → Cloudflare.
  2. Cloudflare → http://example.com → your server.
  3. WordPress sees plain HTTP. Your Site URL is https://example.com.
  4. WordPress emits a 301 redirect to the HTTPS version to match its configured URL.
  5. Browser follows the redirect → back to step 1.

Browsers cap redirects at about 20 hops and show ERR_TOO_MANY_REDIRECTS. The site is unreachable until you break the loop.

Quick fix — tell WordPress to trust the forwarded-proto header

if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && 'https' === $_SERVER['HTTP_X_FORWARDED_PROTO'] ) {
    $_SERVER['HTTPS'] = 'on';
}

Cloudflare (and almost every other TLS terminator) sets the X-Forwarded-Proto header to https so the origin knows the visitor is on a secure connection. This snippet checks for that header and promotes $_SERVER['HTTPS'] to 'on' — now WordPress thinks the request is already HTTPS and skips the redirect.

Place the snippet above the /* That's all, stop editing! */ comment in wp-config.php. The assignment has to happen before WordPress loads its core, which is why it sits in config rather than in theme code.

wordpress too many redirects https — X-Forwarded-Proto header breaks the Cloudflare flexible SSL loop

Blunter alternative — unconditional HTTPS=on

$_SERVER['HTTPS'] = 'on';

Lies to WordPress regardless of the actual request scheme. Works when your origin is only reachable through Cloudflare (Cloudflare’s proxy IPs whitelisted at the firewall, direct origin IP blocked). If your origin accepts raw HTTP from anywhere, an attacker who hits the HTTP port would trigger WordPress to emit HTTPS URLs / secure-flagged cookies over an insecure connection — bad. Prefer the conditional form unless you’ve locked down direct origin access.

The proper long-term fix

Flexible SSL is a quick-and-dirty convenience. For anything you’d leave running for months:

  1. Install a real certificate on the origin — Let’s Encrypt via certbot (see the .htaccess exclude for ACME challenges) or Cloudflare’s free Origin Certificate.
  2. In Cloudflare → SSL/TLS → Overview, switch the mode from Flexible to Full (strict).
  3. WordPress now sees real HTTPS end-to-end. Remove the wp-config.php workaround.

The visible difference is zero — but Full (strict) means your origin is actually protected instead of just looking protected to the visitor.

Frequently asked questions

Why does wordpress too many redirects https happen behind Cloudflare?

Cloudflare’s Flexible SSL mode serves the visitor over HTTPS but talks to your origin over plain HTTP. WordPress sees an HTTP request and, seeing the Site URL set to https://, redirects to https://. Cloudflare terminates TLS again, forwards HTTP, WordPress redirects — infinite loop. The fix is telling WordPress to trust Cloudflare’s HTTPS signal rather than relying on the request scheme it actually sees.

Is $_SERVER['HTTPS'] = 'on' always safe?

Only when you control the proxy chain. Setting HTTPS unconditionally makes WordPress behave as if every request is secure — fine behind a trusted Cloudflare / load balancer that terminates TLS, risky if your origin is directly reachable over plain HTTP (an attacker could hit the HTTP port and WordPress would still emit HTTPS URLs in cookies). The conditional form that checks HTTP_X_FORWARDED_PROTO is safer because it only lies about HTTPS when the proxy said so.

What’s the real long-term fix?

Switch Cloudflare’s SSL mode from Flexible to Full (strict), install a real certificate on the origin (Let’s Encrypt via certbot, or Cloudflare’s free Origin Certificate), and let WordPress see actual HTTPS end-to-end. The $_SERVER['HTTPS'] patch works but it’s a workaround; the proper fix eliminates the HTTP hop entirely.

Does this apply to AWS ALB / nginx reverse-proxy setups too?

Yes — any TLS terminator that forwards HTTP to the origin produces the same redirect loop. AWS Application Load Balancer, nginx reverse proxy, Vercel, and most managed hosts set the X-Forwarded-Proto: https header, so the conditional form below works unchanged. Check var_dump($_SERVER) to confirm which header your stack sets — some use HTTP_X_FORWARDED_SSL or a custom header instead.

Where in wp-config.php does the fix go?

Above the /* That's all, stop editing! Happy publishing. */ comment — and before the require_once ABSPATH . 'wp-settings.php'; line that follows. WordPress reads the file top-to-bottom, and your $_SERVER['HTTPS'] assignment has to run before WordPress checks the server scheme.

Related guides

  • How to Exclude .well-known from Redirection for Let’s Encrypt in Laravel — the ACME challenge step for real origin certificates.
  • How to Fix cURL Error 60 SSL Certificate Problem in Laravel — the sibling “SSL problem from the other direction.”
  • How to Disable Revisions and Autosave in WordPress — another wp-config.php tweak.
  • How to Login a User Programmatically in WordPress — cookie/session considerations for mixed-scheme setups.

References

Cloudflare SSL modes: developers.cloudflare.com/ssl/origin-configuration/ssl-modes. WordPress is_ssl() internals: developer.wordpress.org/reference/functions/is_ssl.

TAGGED:configurationphpSecuritytroubleshootingwordpress

Sign Up For Daily Newsletter

Be keep up! Get the latest breaking news delivered straight to your inbox.
[mc4wp_form]
By signing up, you agree to our Terms of Use and acknowledge the data practices in our Privacy Policy. You may unsubscribe at any time.
Share This Article
Facebook Copy Link Print
Previous Article WordPress wp_dequeue_style priority 9999 runs after plugin enqueues How to Deregister or Remove a CSS File in WordPress (wp_dequeue_style Not Working)
Next Article WordPress default posts per page — get_option reads the Settings Reading value How to Get the Default Posts Per Page Value in WordPress
Leave a Comment

Leave a Reply Cancel reply

You must be logged in to post a comment.

FacebookLike
XFollow
PinterestPin
InstagramFollow
Most Popular
Bun runtime — faster JS toolkit replacing npm in Laravel projects
How to Install Bun Runtime on Ubuntu (And Use It in a Laravel Project)
May 24, 2026
Tailscale mesh — peer-to-peer connections between devices, coordination server
How to Install Tailscale on Ubuntu (Zero-Config Mesh VPN for Self-Hosters)
May 24, 2026
Caddy server — automatic HTTPS, 3-line Caddyfile vs 25-line nginx config
How to Install Caddy Server on Ubuntu (Automatic HTTPS, Drop-in nginx Alternative)
May 24, 2026
Cloudflare Tunnel — outbound-only connection from server, no inbound port forward
How to Install Cloudflare Tunnel on Ubuntu (Expose Local Services, No Port Forwarding)
May 24, 2026
WireGuard encrypted tunnel between server and clients with lock icons
How to Set Up WireGuard VPN on Ubuntu (Server, Linux Client, and iOS)
May 24, 2026

You Might Also Like

Run a Node.js application from a Windows .bat file
OS

How to Run a Node.js Application from a Windows .bat File

5 Min Read
WooCommerce homepage filter to hide out of stock products
Web Development

Hide Out of Stock Products from Homepage in WooCommerce (Keep Them Visible Elsewhere)

5 Min Read
PHP delete array element — unset, array_splice, array_filter, array_search
Web Development

How to Delete an Element from a PHP Array

7 Min Read
Install HandBrake CLI on Linux with Flatpak
Server Management

How to Install HandBrake CLI on Linux (Flatpak)

5 Min Read
How7o

We provide tips, tricks, and advice for improving websites and doing better search.

Tools

  • Age Calculator
  • Word Counter
  • Image Upscaler
  • Password Generator
  • QR Code Generator
  • See all tools→

Pranks

  • Fake Blue Screen Prank
  • Hacker Typer
  • Fake iMessage Generator
  • Windows XP Crash Prank
  • Windows 11 Update Prank
  • See all prank screens →

Company

  • About Us
  • Blog
  • Contact
  • Privacy Policy
  • Terms of Service
  • Sitemap
© 2024–2026 How7o. All rights reserved.
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?