skip to content

A Cloudflare zone set to Flexible fronts an origin that redirects HTTP to HTTPS, and browsers now show ERR_TOO_MANY_REDIRECTS; why, and what is the right fix?

level: seniorimportance: must knowfreq 65%

answer

  1. which scheme reaches the origin
  2. the origin never sees HTTPS
  3. redirect at the edge instead
  4. Full (strict) with an origin certificate

basics

~20 s

Flexible always fetches the origin over HTTP, so the origin's HTTPS redirect fires even for visitors already on HTTPS, and the browser loops. Install an origin certificate, switch to Full (strict), and redirect HTTP visitors at the edge with Always Use HTTPS.

solid answer

~40 s

Under **Flexible**, Cloudflare talks to the origin over plain HTTP no matter how the visitor connected. The origin sees an HTTP request, answers `301` to `https://`, the browser follows it to Cloudflare over HTTPS, and Cloudflare again fetches over HTTP, so the redirect repeats until the browser gives up with `ERR_TOO_MANY_REDIRECTS`. The right fix is to make the origin leg HTTPS: install a certificate (a free Origin CA certificate works for proxied records) and move to **Full (strict)**, after which the origin's redirect is satisfied. Do the HTTP-to-HTTPS redirect at the edge with **Always Use HTTPS**, or a Single Redirect for part of the site, rather than at the origin. Deleting the origin redirect and staying on Flexible also ends the loop, but leaves the origin leg in cleartext.

code

bash · 5 lines
bash
curl --request PATCH \
  "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/settings/ssl" \
  --header "Authorization: Bearer $CF_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{"value":"strict"}'

go deeper

for a junior

Recall that Flexible uses plain HTTP to the origin, so an origin that forces HTTPS can never be satisfied, and that Full (strict) with an origin certificate is the fix.

for a middle

Walk through the request sequence step by step and explain why Always Use HTTPS alone does not help while moving the redirect to the edge does.

for a senior

Plan the switch: certificate on the origin, 525 and 526 as the failure signals, the cache-key change that sends misses to the origin, and the mirror-image loop if the origin redirects HTTPS to HTTP.

for a principal

Argue for one owner of redirects, the edge, and a zone floor of Full (strict), so that onboarding a site with an existing HTTPS redirect cannot reproduce this outage.

## How the loop forms With the **Flexible** encryption mode, Cloudflare encrypts the visitor's connection to the edge but **always fetches from the origin over plain HTTP**. An origin configured to "force HTTPS" judges each request by the connection it arrived on, and every request from Cloudflare arrives on HTTP. The sequence: 1. The browser requests `https://www.example.com/` from Cloudflare. 2. Cloudflare, under Flexible, requests `http://www.example.com/` from the origin. 3. The origin sees HTTP and answers `301 Moved Permanently` with `Location: https://www.example.com/`. 4. Cloudflare passes the redirect back, the browser follows it, and the cycle starts again at step 1. ```plaintext browser -> Cloudflare : GET https://www.example.com/ Cloudflare -> origin : GET http://www.example.com/ origin -> browser : 301 Location: https://www.example.com/ browser -> Cloudflare : GET https://www.example.com/ (repeats) ``` The browser eventually stops and shows `ERR_TOO_MANY_REDIRECTS` or "The page isn't redirecting properly". Cloudflare's documentation names this case directly: if the origin redirects HTTP to HTTPS, do not use Flexible. ## Why it often appears right after onboarding The usual history is a site that already forced HTTPS before it was moved behind Cloudflare, combined with a zone set to Flexible because the origin certificate looked like extra work. It can also appear when someone adds a "force HTTPS" plugin to an origin whose zone has always been Flexible. Two clues identify this cause quickly: the loop affects every page rather than one path, and requesting the origin directly over HTTP returns the same `301` to `https://` that the browser keeps receiving through Cloudflare. ## The fixes, ranked | Fix | Ends the loop | Origin leg afterwards | |---|---|---| | Install a certificate, switch to **Full (strict)** | yes | encrypted and verified | | Switch to **Full** with a self-signed certificate | yes | encrypted, not verified | | Delete the origin redirect, stay on **Flexible** | yes | cleartext | | Turn on **Always Use HTTPS**, stay on **Flexible** | no | cleartext | The last row is a common wrong turn. Always Use HTTPS redirects HTTP visitors at the edge, but HTTPS visitors are still fetched over HTTP under Flexible, so the origin keeps redirecting them. The preferred path: - Issue a certificate for the origin. A **Cloudflare Origin CA** certificate is free and trusted by Cloudflare, which is enough when the origin is only reached through proxied records; a publicly trusted certificate also works. - Make sure the origin accepts HTTPS on port 443 with that certificate, then set the mode to **Full (strict)**. Now Cloudflare fetches HTTPS visitors over HTTPS, and the origin's redirect has nothing left to redirect. - Move the HTTP-to-HTTPS redirect to the edge with **Always Use HTTPS**, or with a **Single Redirect** when only part of the site supports HTTPS. Cloudflare recommends redirecting at the edge rather than at the origin; it is faster and does not depend on the mode. ## Switching safely - **Expect 525 or 526 if the origin is not ready.** A failed handshake shows as 525; a certificate that Full (strict) rejects shows as 526. - **Expect a colder cache.** With the default cache key, the scheme Cloudflare uses to reach the origin is part of the key, so moving from Flexible to Full or Full (strict) gives cached objects new keys and sends a wave of misses to the origin. - **Know the port rule.** Flexible applies only to HTTPS on port 443; other HTTPS ports already fall back to Full behaviour, so those hostnames may have worked all along. - A stopgap some origins allow is to base the redirect on the `X-Forwarded-Proto` header, which Cloudflare sends to identify the protocol the visitor used. It ends the loop but leaves the origin leg in cleartext, so treat it as temporary. ## The mirror-image loop The same pattern runs the other way. Under **Full** or **Full (strict)**, or with **Always Use HTTPS** on, an origin that redirects HTTPS to HTTP loops just as badly: the edge sends the visitor to HTTPS, the origin sends them back. The fix there is to delete the origin's HTTP redirect. In every variant, the rule of thumb is the same: decide the scheme once, at the edge, and keep the origin from second-guessing it.

  • Why does turning on Always Use HTTPS not cure the Flexible loop?
    Always Use HTTPS only redirects visitors who arrive over HTTP. Visitors already on HTTPS are still fetched from the origin over HTTP under Flexible, so the origin keeps answering with its redirect to HTTPS and the loop continues. The origin leg has to become HTTPS, or the origin redirect has to go.
  • Can a zone on Full (strict) still hit ERR_TOO_MANY_REDIRECTS?
    Yes, when the origin redirects HTTPS to HTTP, or when two redirects disagree, for example a Cloudflare redirect rule sending a.example.com to http://b.example.com and another sending it back. The fix is to remove the origin's HTTP redirect and keep a single owner for redirects at the edge.

  • Turning on Always Use HTTPS fixes a Flexible redirect loop.
  • The loop means Cloudflare cached a bad 301; purging the cache fixes it.
  • Deleting the origin redirect and staying on Flexible secures the site.
  • Flexible sends HTTPS visitors to the origin over HTTPS.
  • Switching from Flexible to Full (strict) never changes any cache keys.