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:
siteurlandhomedrift,FORCE_SSL_ADMIN, proxy-blind scheme detection inwp-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 → EditandZone → 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.
curl7.21.3 or newer for--resolve, andopenssl. The%{scheme}write-out variable used at the end needs curl 7.52 or newer. macOS ships LibreSSL rather than OpenSSL; thes_clientoutput is formatted slightly differently, but the subject, issuer and dates all appear.- The origin’s real IP address. Once a record is proxied,
digreturns Cloudflare anycast addresses, not your server — read it from the DNS tab, your provider’s console, orip -4 addron the box. Examples below use203.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.
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.
Step-by-step
-
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 thelocationvalue alternates between two different hostnames, skip to step 10 and to Troubleshooting — that loop is not about TLS. -
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'flexibleThe dashboard equivalent is SSL/TLS → Overview. Valid values are
off,flexible,fullandstrict. -
Ask the origin directly what it does with plain HTTP.
--resolvesends the request past Cloudflare while keeping the correctHostheader 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
flexiblein step 2 plus this redirect in step 3 is a complete diagnosis. Note the absence of aserver: cloudflareheader — that confirms you really did bypass the edge. -
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 -datessubject=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 GMTconnect: Connection refusedmeans nothing is listening on 443. A self-signed subject, an expirednotAfter, or aCNthat 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. -
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 nginxnginx: configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successfulOn Apache the equivalent is
apachectl configtest, which printsSyntax OKbefore 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. -
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 strictRe-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. -
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 homehttps://example.com https://example.comIf 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-runSuccess: Updated 'siteurl' option. +------------+--------------+--------------+------+ | Table | Column | Replacements | Type | +------------+--------------+--------------+------+ | wp_posts | post_content | 412 | SQL | +------------+--------------+--------------+------+ Success: 412 replacements to be made.Re-run without
--dry-runto 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 thewp_optionstable, or pinned temporarily withWP_HOMEandWP_SITEURLconstants inwp-config.php. -
Teach WordPress about the proxy. WordPress decides “am I on HTTPS?” from
$_SERVER['HTTPS'], which is empty behind any TLS-terminating proxy. WithFORCE_SSL_ADMINset, it therefore redirects/wp-admin/to HTTPS forever, even when the visitor is already there.wp config get FORCE_SSL_ADMIN --type=constant1Add the following to
wp-config.phpabove therequire_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.phprequire 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. -
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=nameThen 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
.htaccessabove 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
mapgoes in thehttpblock and theserverblock 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 nginxand expect the same twosyntax is oklines as in step 5. -
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
sslaction 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.