How to fix SSL loop error on Cloudflare?

An SSL loop on Cloudflare (often shown as “Too many redirects” or Cloudflare error ERR_TOO_MANY_REDIRECTS) happens when Cloudflare and your origin server keep redirecting each other between HTTP and HTTPS.

Here’s a step-by-step guide to fix it:


Why SSL loops happen

  1. Visitor → HTTPS → Cloudflare
  2. Cloudflare → HTTP → origin server
  3. Origin server → redirects to HTTPS
  4. Cloudflare repeats step 2 → infinite loop

This is caused by mismatched SSL settings between Cloudflare and your server.


Step 1: Set the correct Cloudflare SSL mode

Go to Cloudflare → SSL/TLS → Overview

Correct setting

  • Full (Strict)

Explanation of modes

ModeProblem
OffNo HTTPS
FlexibleCauses SSL loops
FullNo certificate validation
Full (Strict)Correct and secure

Flexible SSL is the most common cause of redirect loops.


Step 2: Install a valid certificate on the origin server

Your server must have a valid certificate if using Full (Strict).

Options:

  • Public CA (Let’s Encrypt, DigiCert, etc.)
  • Cloudflare Origin Certificate (trusted only by Cloudflare, valid up to 15 years)

Step 3: Fix HTTPS redirects on the origin server

Apache

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Nginx

if ($http_x_forwarded_proto = "http") {
  return 301 https://$host$request_uri;
}

This ensures redirects happen only if the visitor used HTTP, preventing loops.


Step 4: Let Cloudflare handle HTTPS redirects

  • Cloudflare → SSL/TLS → Edge Certificates → Always Use HTTPS
  • Remove HTTPS redirects from the server to avoid conflicts

Step 5: WordPress-specific fix

wp-config.php

define('FORCE_SSL_ADMIN', true);

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

Check that WordPress Address and Site Address use https://.


Step 6: Clear caches

  • Purge Cloudflare cache
  • Clear browser cache
  • Clear server cache if any

Quick Fix Checklist

  • Cloudflare SSL mode = Full (Strict)
  • Origin server has valid certificate
  • No Flexible SSL
  • Redirects respect X-Forwarded-Proto
  • Cloudflare handles HTTPS redirect
  • WordPress URLs set to HTTPS

Verification

curl -I https://example.com
  • Should return HTTP 200 or 301 with correct Location
  • No repeating redirects
openssl s_client -connect example.com:443 -servername example.com
  • Certificate should load without errors

Common causes summary

CauseFix
Flexible SSLSwitch to Full (Strict)
Origin has no certificateInstall origin certificate
Double redirectsLet Cloudflare handle HTTPS
WordPress misdetects HTTPSFix wp-config.php
CDN + server redirect conflictRespect X-Forwarded-Proto

Leave a Reply

Your email address will not be published. Required fields are marked *