How7o
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Reading: Fix ERR_TOO_MANY_REDIRECTS in WordPress After Switching to HTTPS
Share
Subscribe Now
How7oHow7o
Font ResizerAa
  • Marketing
  • OS
  • Features
  • Guide
  • Complaint
  • Advertise
Search
  • Home
  • Tools
  • Prank Screens
  • Contact
  • Blog
Follow US
Copyright © 2014-2023 Ruby Theme Ltd. All Rights Reserved.
How7o > Blog > 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.
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

Subscribe Now

Subscribe to our newsletter to get our newest articles instantly!
Most Popular
Display PHP errors — ini_set + php.ini configuration
How to Display PHP Errors
May 10, 2026
PHP convert string to uppercase — strtoupper and mb_strtoupper
How to Convert a String to Uppercase in PHP
May 10, 2026
PHP string to float conversion with cast, regex cleanup, NumberFormatter
How to Convert a String to Float in PHP
May 10, 2026
PHP merge arrays without duplicates — union operator and array_unique
How to Combine Two Arrays Without Duplicates in PHP
May 10, 2026
PHP delete array element — unset, array_splice, array_filter, array_search
How to Delete an Element from a PHP Array
May 10, 2026

You Might Also Like

Laravel last inserted ID — Eloquent save populates model primary key illustration
Web Development

How to Retrieve the Last Inserted ID in Laravel Eloquent

8 Min Read
MySQL top CPU usage — PROCESSLIST snapshot and performance_schema digest
Server Management

How to Check Which MySQL Database or User Is Using the Most CPU

8 Min Read
Install a specific version of a package using Composer (composer require vendor/package:2.1.0)
Web Development

Install a Specific Version of a Package Using Composer (Exact Version + Examples)

5 Min Read
Automatic logout timeout for command line in Ubuntu (TMOUT 300s)
Server Management

Automatic Logout Timeout for Command Line in Ubuntu (TMOUT 300s)

5 Min Read
How7o

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

Latest News

  • SEO Audit Tool
  • Client ReferralsNew
  • Execution of SEO
  • Reporting Tool

Resouce

  • Google Search Console
  • Google Keyword Planner
  • Google OptimiseHot
  • SEO Spider

Get the Top 10 in Search!

Looking for a trustworthy service to optimize the company website?
Request a Quote
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?