Skip to content

Cloudflare ERR_TOO_MANY_REDIRECTS: fixing the Flexible SSL 301 loop

The zone is on Flexible SSL, Cloudflare fetches your origin over plain HTTP, and the origin answers 301 to HTTPS forever. Confirm the loop with curl, fix it permanently with an origin certificate and Full (strict), and handle the WordPress, Apache and nginx variants.

ERR_TOO_MANY_REDIRECTS on a Cloudflare-proxied hostname is almost always one specific failure: the zone’s SSL/TLS mode is Flexible, so the edge fetches your origin over plain HTTP on port 80, and the origin answers every plain-HTTP request with a 301 to https://. Cloudflare relays that redirect to a browser that is already on HTTPS, the browser asks for the same URL again, and the two sides trade the identical 301 until Chrome gives up at roughly twenty hops. One command tells you in five seconds whether that is what you are looking at:

curl -sIL --max-redirs 6 https://example.com/ 2>&1 | grep -iE '^HTTP/|^location|^server:'
HTTP/2 301
server: cloudflare
location: https://example.com/
HTTP/2 301
server: cloudflare
location: https://example.com/
curl: (47) Maximum (6) redirects followed

The same status, the same location value, server: cloudflare on every hop: that is the Flexible loop. The permanent fix is two moves — put a certificate on the origin, then switch the zone to Full (strict) — and steps 1 through 6 below do exactly that. If the location value changes between hops instead of repeating, you have a different loop; the triage diagram in the next section tells you which one.

What you’ll accomplish

  • Prove from the command line, in about a minute, whether Flexible SSL is the cause instead of guessing from a dashboard toggle.
  • Install a certificate on the origin and verify that the edge-to-origin hop actually negotiates TLS.
  • Move the zone to Full (strict) so the loop stops without deleting the origin’s HTTP-to-HTTPS redirect.
  • Fix the WordPress variants that keep the loop alive after the mode change: siteurl and home drift, FORCE_SSL_ADMIN, proxy-blind scheme detection in wp-config.php, and a plugin redirecting in parallel with the edge.
  • Rule out the two impostors — an apex and www redirect cycle, and Always Use HTTPS colliding with an origin rule.

Prerequisites

  • A hostname proxied through Cloudflare (the orange cloud). If the record is DNS-only, none of this applies and the loop is entirely on your origin.
  • Zone-level dashboard access, or an API token scoped to Zone → Zone Settings → Edit and Zone → Zone → Read.
  • Shell access to the origin, or a control panel that can install a certificate. On cPanel that is SSL/TLS → Manage SSL sites; the rest of this guide assumes a shell.
  • curl 7.21.3 or newer for --resolve, and openssl. The %{scheme} write-out variable used at the end needs curl 7.52 or newer. macOS ships LibreSSL rather than OpenSSL; the s_client output is formatted slightly differently, but the subject, issuer and dates all appear.
  • The origin’s real IP address. Once a record is proxied, dig returns Cloudflare anycast addresses, not your server — read it from the DNS tab, your provider’s console, or ip -4 addr on the box. Examples below use 203.0.113.10; substitute yours.
  • WP-CLI 2.x if the site is WordPress, plus a database backup before any search-replace. Every WP-CLI step here has a dashboard or SQL equivalent, so the tool is convenience rather than a hard requirement.
  • The SSL/TLS modes behave the same on Free, Pro, Business and Enterprise. Nothing in this fix is plan-gated.

How it works

A proxied hostname has two independent TLS hops. The browser-to-edge hop is HTTPS as soon as an edge certificate exists, and that is the hop the padlock describes. The edge-to-origin hop is the one the SSL/TLS mode controls, and it is invisible from a browser. Cloudflare’s per-mode reference is SSL/TLS encryption modes, and the practical comparison lives in Flexible vs Full vs Full (strict).

In Flexible mode, Cloudflare always contacts the origin over http:// on port 80, regardless of what the visitor used. Your origin then does the thing every hardening guide told it to do: it sees an insecure request and issues a permanent redirect to the HTTPS version. Cloudflare does not rewrite that Location header — it is a normal upstream response, so it goes straight back to the visitor.

Request path of the Flexible SSL redirect loop, showing the scheme on each hop between browser, Cloudflare edge and origin server

The subtlety that trips people up is that Cloudflare still reports the visitor’s scheme in the X-Forwarded-Proto and CF-Visitor request headers, even in Flexible mode. So the header says https while the actual TCP connection is plaintext. Origin redirect rules normally key on the connection itself — Apache’s %{HTTPS}, nginx’s $scheme, PHP’s $_SERVER['HTTPS'] — which correctly report “not secure”, and the redirect fires. That gap between what the headers claim and what the socket is doing is the entire bug.

WordPress is the most frequent casualty, for a reason worth understanding before you start typing. Its canonical redirect enforces the scheme stored in the siteurl option on every single request, in PHP, before any of your web server rules get a say. So a WordPress site can loop even after the SSL mode is correct, because a second redirector is still firing. That is why the diagram below splits the symptom into three verdicts rather than one.

Triage tree matching the curl output to one of three verdicts: Flexible SSL loop, canonical hostname conflict, or WordPress scheme drift

Step-by-step

Before and after comparison of Flexible and Full (strict), showing where TLS terminates in each mode and why the loop stops

  1. Confirm the signature, with a cap on the hops. This is the command from the top of the page. Without --max-redirs, curl will happily follow the loop for a long time.

    curl -sIL --max-redirs 6 https://example.com/ 2>&1 | grep -iE '^HTTP/|^location|^server:'

    The failure signature is the same status and the same target repeating, ending in curl: (47) Maximum (6) redirects followed. If instead the location value alternates between two different hostnames, skip to step 10 and to Troubleshooting — that loop is not about TLS.

  2. Read the zone’s actual SSL/TLS mode. Dashboards get changed by other people; ask the API.

    curl -s "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/settings/ssl" \
      -H "Authorization: Bearer $CF_API_TOKEN" | jq -r '.result.value'
    flexible

    The dashboard equivalent is SSL/TLS → Overview. Valid values are off, flexible, full and strict.

  3. Ask the origin directly what it does with plain HTTP. --resolve sends the request past Cloudflare while keeping the correct Host header and SNI.

    curl -sI --resolve example.com:80:203.0.113.10 http://example.com/ | grep -iE '^HTTP/|^location'
    HTTP/1.1 301 Moved Permanently
    Location: https://example.com/

    Mode flexible in step 2 plus this redirect in step 3 is a complete diagnosis. Note the absence of a server: cloudflare header — that confirms you really did bypass the edge.

  4. Check whether the origin can already speak TLS. This decides whether you can flip the mode right now or need to install a certificate first.

    openssl s_client -connect 203.0.113.10:443 -servername example.com </dev/null 2>/dev/null \
      | openssl x509 -noout -subject -issuer -dates
    subject=CN = example.com
    issuer=C = US, O = Let's Encrypt, CN = R11
    notBefore=Jul  2 08:14:31 2026 GMT
    notAfter=Sep 30 08:14:30 2026 GMT

    connect: Connection refused means nothing is listening on 443. A self-signed subject, an expired notAfter, or a CN that does not match the hostname all mean Full (strict) will reject the origin. Any of those sends you to step 5; a valid certificate lets you jump to step 6.

  5. Put a real certificate on the origin. A Cloudflare Origin CA certificate is the fastest route: SSL/TLS → Origin Server → Create Certificate, validity up to 15 years, and it is trusted by Full (strict) by design. It is not publicly trusted, so it only works on hostnames that stay proxied. A Let’s Encrypt or AutoSSL certificate works equally well and survives the proxy being turned off, but its renewal has to keep working — either use a DNS-01 challenge or confirm that /.well-known/acme-challenge/ is reachable through the edge. The full procedure for both is in origin certificates end to end. After installing, reload the web server and confirm the config parses:

    nginx -t && systemctl reload nginx
    nginx: configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful

    On Apache the equivalent is apachectl configtest, which prints Syntax OK before you reload. Re-run step 4 until it returns the certificate you just installed. Do not skip that check: switching to Full (strict) against a broken origin certificate replaces the loop with a Cloudflare error 526.

  6. Switch the zone to Full (strict). The change takes effect within seconds and needs no cache purge. For most non-WordPress sites, the loop stops here.

    curl -s -X PATCH "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/settings/ssl" \
      -H "Authorization: Bearer $CF_API_TOKEN" \
      -H "Content-Type: application/json" \
      --data '{"value":"strict"}' | jq -r '.success, .result.value'
    true
    strict

    Re-run the step 1 command now. If it returns a single HTTP/2 200, you are done and the remaining steps are hardening. If it still loops and the site is WordPress, continue.

  7. Make WordPress agree with itself. Both options must carry the same scheme and the same hostname. This is the single most common reason a WordPress site keeps looping after the mode is correct.

    wp option get siteurl
    wp option get home
    https://example.com
    https://example.com

    If either still says http://, update it and then rewrite the content that hardcoded the old scheme:

    wp option update siteurl 'https://example.com'
    wp search-replace 'http://example.com' 'https://example.com' --all-tables --skip-columns=guid --dry-run
    Success: Updated 'siteurl' option.
    +------------+--------------+--------------+------+
    | Table      | Column       | Replacements | Type |
    +------------+--------------+--------------+------+
    | wp_posts   | post_content | 412          | SQL  |
    +------------+--------------+--------------+------+
    Success: 412 replacements to be made.

    Re-run without --dry-run to apply. Keep --skip-columns=guid: rewriting GUIDs makes feed readers treat every post as new. If the loop has locked you out of the admin and WP-CLI is unavailable, the same two rows can be set from phpMyAdmin in the wp_options table, or pinned temporarily with WP_HOME and WP_SITEURL constants in wp-config.php.

  8. Teach WordPress about the proxy. WordPress decides “am I on HTTPS?” from $_SERVER['HTTPS'], which is empty behind any TLS-terminating proxy. With FORCE_SSL_ADMIN set, it therefore redirects /wp-admin/ to HTTPS forever, even when the visitor is already there.

    wp config get FORCE_SSL_ADMIN --type=constant
    1

    Add the following to wp-config.php above the require_once ABSPATH . 'wp-settings.php'; line, so the rest of WordPress sees a consistent picture:

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

    Two cautions. Place it above the wp-settings.php require or WordPress will already have decided. And trust that header only when a proxy you control is the sole path to the origin — otherwise anyone can send it, so pair this with a firewall that admits only Cloudflare’s address ranges.

  9. Find the second redirector. Once the scheme is right, a lingering loop usually means two things are redirecting at once. Check the active plugin list for one that ships its own HTTPS enforcement — Really Simple SSL and most cache plugins do:

    wp plugin list --status=active --field=name

    Then make the origin’s own redirect proxy-aware rather than deleting it. Redirecting HTTP to HTTPS at the origin is correct hygiene; it only looped because Flexible downgraded the fetch. The version below checks the forwarded header first and the connection second, so it never fires behind a proxy that is doing its job, and still protects direct hits on port 80. In Apache, inside .htaccess above the WordPress rewrite block, or in a vhost:

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

    In nginx, the map goes in the http block and the server block handles port 80:

    map $http_x_forwarded_proto $client_scheme {
        ""      $scheme;
        default $http_x_forwarded_proto;
    }
    
    server {
        listen 80;
        server_name example.com www.example.com;
    
        if ($client_scheme != "https") {
            return 301 https://$host$request_uri;
        }
    }

    Reload with nginx -t && systemctl reload nginx and expect the same two syntax is ok lines as in step 5.

  10. Check the edge for per-URL overrides. A zone can read Full (strict) on the Overview page and still be Flexible for one hostname, because Configuration Rules and legacy Page Rules can override the SSL mode per URL pattern. Check the edge-level HTTPS toggle and any Page Rules:

    curl -s "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/settings/always_use_https" \
      -H "Authorization: Bearer $CF_API_TOKEN" | jq -r '.result.value'
    
    curl -s "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/pagerules" \
      -H "Authorization: Bearer $CF_API_TOKEN" \
      | jq -r '.result[] | {target: .targets[0].constraint.value, actions: [.actions[].id]}'
    on
    {
      "target": "*example.com/*",
      "actions": ["ssl"]
    }

    An ssl action in that output is a per-URL mode override and needs the same treatment as the zone setting. Configuration Rules live under Rules → Configuration Rules in the dashboard and are worth a visual scan; Redirect Rules are where apex-versus-www loops usually hide.

Validate it works

Confirm the public path first. One response, no location header:

curl -sIL --max-redirs 6 https://example.com/ | grep -iE '^HTTP/|^location'
HTTP/2 200

Confirm the origin hop independently, past the edge, over TLS:

curl -sI --resolve example.com:443:203.0.113.10 https://example.com/ | head -1
HTTP/1.1 200 OK

Confirm that the plain-HTTP entry point still redirects exactly once, rather than not at all:

curl -s https://example.com/ -o /dev/null -w '%{http_code} %{num_redirects} %{scheme}\n'
curl -s http://example.com/ -o /dev/null -w '%{http_code} %{num_redirects} %{scheme}\n'
200 0 https
200 1 https

On WordPress, check the admin path separately, because it has its own redirect logic:

curl -sIL --max-redirs 6 https://example.com/wp-admin/ | grep -iE '^HTTP/|^location'
HTTP/2 302
location: https://example.com/wp-login.php?redirect_to=%2Fwp-admin%2F
HTTP/2 200

One hop to the login form and a 200 is the correct end state for a logged-out client. Finally, confirm the mode really persisted, since a Configuration Rule can quietly re-override it:

curl -s "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/settings/ssl" \
  -H "Authorization: Bearer $CF_API_TOKEN" | jq -r '.result.value'
strict

Troubleshooting

Cloudflare error 526 right after switching modes. Full (strict) validated the origin certificate and rejected it. Re-run the step 4 check with -showcerts added to openssl s_client and read the chain: the usual causes are an expired certificate, a missing intermediate, or a certificate issued for www.example.com only while the edge requests the apex. Fix the chain, or set the mode back to full for the few minutes it takes — full still encrypts the hop, it just does not validate.

The loop survives and the zone is genuinely Full (strict). Then Flexible was never the cause. The remaining suspects, in order of frequency: a WordPress siteurl still on http:// (step 7); a second proxy between Cloudflare and the application — an ALB, HAProxy, Traefik or a Docker-side nginx — that terminates TLS and forwards plain HTTP without setting X-Forwarded-Proto; or an application-level canonical redirect fighting a web server one.

Only /wp-admin/ loops, the front end is fine. That is FORCE_SSL_ADMIN without the proxy-aware snippet from step 8, or WP_HOME and WP_SITEURL constants in wp-config.php overriding the database values you just corrected. Constants win over options, and wp option get will not show them. Check with wp config get WP_HOME --type=constant.

The location header alternates between apex and www. Two owners disagree about the canonical hostname — typically a Cloudflare Redirect Rule sending apex to www while the origin vhost sends www back to apex. This loop is unrelated to TLS and will not be fixed by changing the SSL mode. Pick one canonical hostname, implement the redirect in exactly one place, and delete the other.

Every command says it is fixed, but the browser still loops. Browsers cache 301 responses aggressively and an HSTS header makes the scheme upgrade sticky on top of that. Test in a private window, or clear site data for the hostname. If a Cache Rule made the redirect cacheable at the edge, purge the zone cache as well. curl starts with no cache, which is exactly why it is the arbiter here.

When this is the wrong approach

If the DNS record is grey-clouded, Cloudflare is not in the request path at all and no SSL/TLS mode change will do anything — the loop is entirely inside your own stack. If the origin sits behind a second load balancer that you do not control, fixing X-Forwarded-Proto there is the real work and the Cloudflare mode is a distraction.

Cloudflare Origin CA is a private CA. If a compliance regime requires a publicly trusted certificate on every hop, or if you ever need the hostname to work unproxied, use Let’s Encrypt or a commercial certificate instead and keep renewal automated. For stronger origin protection than Full (strict) alone, pair it with Authenticated Origin Pulls so the origin refuses connections that did not come from Cloudflare — that is a separate change and not required to stop this loop.

Finally, the honest stopgap: if you cannot touch the origin today, teaching the application to trust X-Forwarded-Proto stops the loop even while the zone stays on Flexible, because the header carries the visitor’s real scheme. The site will load. The edge-to-origin hop stays cleartext across the public internet, so treat that as something measured in days, not as the fix. Cloudflare’s own reference for the mode behaviour is developers.cloudflare.com/ssl/.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.