Wiki / Cloudflare / Secure connection and redirects

Cloudflare ERR_TOO_MANY_REDIRECTS: causes and fixes

ERR_TOO_MANY_REDIRECTS means the browser was sent in a circle of redirects. Behind Cloudflare the circle usually runs between a Cloudflare setting and a redirect on your server. The pair we see most often is Flexible mode and a server that redirects HTTP to HTTPS: Cloudflare asks the server over HTTP, the server answers “go to HTTPS”, and the visitor is already there. One curl command shows which of the three loops on this page you have. In our test the loop was gone within five seconds of changing the mode to Full.

Aleksandr IzmalkovFacts checked:

Urgency
High: every visitor whose request enters the loop gets the error, and search engine crawlers get the same redirects
Time to fix
Changing a setting in Cloudflare or a redirect on the server takes minutes; installing a certificate on the server, if it has none, takes longer
When the fix is visible
In our test, polled about once a second, the last 301 came 3.5 seconds after the mode was switched and the first 200 at 4.6 seconds. A browser may store a 301 redirect it has already seen, so check with curl or in a private window
What you need
Access to the Cloudflare dashboard, a terminal with curl, and for two of the three loops access to the server's configuration or to the hosting provider's support

What you see

  • Chrome and Edge show “This page isn’t working: example.com redirected you too many times”, code ERR_TOO_MANY_REDIRECTS. Firefox shows “The page isn’t redirecting properly”.
  • curl told to follow redirects stops with error 47: Maximum (5) redirects followed in our test, where the limit was set to five.
  • It started when the domain was added to Cloudflare, or right after the encryption mode, Always Use HTTPS or a redirect rule was changed.
  • The site opens when you connect to the server directly, past Cloudflare.
Chrome error page: This page isn’t working, redirected you too many times, ERR_TOO_MANY_REDIRECTS
What Chrome shows when a site redirects in a loop. Reproduced with a looping test server; the name is replaced with example.com.

Why it happens

Behind Cloudflare a request is made twice: from the visitor to Cloudflare and from Cloudflare to your server. The encryption mode decides how the second one is made. In Flexible mode it always goes over plain HTTP to port 80, whatever the visitor used. In Full and Full (strict) mode it uses the visitor's scheme: HTTPS to port 443 for an HTTPS visitor, HTTP to port 80 for an HTTP visitor.

A server that redirects every HTTP request to HTTPS does the right thing when visitors reach it directly. In Flexible mode every request it gets is HTTP, so it redirects every one of them, the HTTPS visitors included. The visitor follows the redirect to the address they are already on, Cloudflare asks the server over HTTP again, and after a number of rounds the browser gives up.

Cloudflare tells the server what the visitor used. In our log the requests of an HTTPS visitor arrived on port 80 with the headers X-Forwarded-Proto: https and CF-Visitor: {"scheme":"https"}. A redirect that ignores these headers loops; a redirect that reads them does not. The other two loops on this page are the same idea with the roles changed: Cloudflare sends visitors to HTTPS while the server sends them to HTTP, or Cloudflare sends one name to another while the server sends it back.

Diagram: the browser asks Cloudflare over HTTPS, Cloudflare in Flexible mode asks the server over HTTP on port 80, the server answers 301 to the HTTPS address, the browser asks the same address again
The Flexible loop. The server never sees an HTTPS request, so it never stops redirecting.

Find the cause

Run the first command from your own computer; it prints the status and the Location of the first six answers. Replace example.com with your name, and in the second command 192.0.2.10 with your server's address (the content of the A record in Cloudflare → DNS → Records). Use the full address that fails, with its path: if visitors type www, test www; if only the login page loops, test that page. If curl prints a connection or TLS error, that error comes first: this page is about chains that end in Maximum (5) redirects followed. The flag -I sends a HEAD request. If the application answers HEAD and GET differently, replace -sSIL with -sSL -D - -o /dev/null: that sends an ordinary GET and prints only the headers. macOS and Linux have curl and grep; on Windows run the commands in Git Bash.

  1. curl -sSIL --max-redirs 5 https://example.com/ | grep -i -E "^HTTP|^location"
    If the answer isIt means
    HTTP/2 301 
    location: https://example.com/
    HTTP/2 301 
    location: https://example.com/
    HTTP/2 301 
    location: https://example.com/
    Every answer points to the address that was just asked. Something behind Cloudflare believes the request was plain HTTP. Go to the next command.
    HTTP/2 301 
    location: http://example.com/
    HTTP/1.1 301 Moved Permanently
    Location: https://example.com/
    HTTP/2 301 
    location: http://example.com/
    The answers alternate between http:// and https://: one side sends visitors to HTTPS and the other to HTTP.Cause: The server redirects HTTPS to HTTP, Cloudflare redirects back ↓
    HTTP/2 301 
    location: https://www.example.com/
    HTTP/2 301 
    location: https://example.com/
    HTTP/2 301 
    location: https://www.example.com/
    The answers alternate between two names: two redirects point at each other. They can sit in Cloudflare, on the server or in the application.Cause: Two redirects point at each other ↓
    HTTP/2 200
    No loop from your computer, and the chain ends on HTTPS. If the browser still shows the error, open the page in a private window: a regular window may replay a 301 it stored earlier.
    HTTP/2 301 
    location: http://example.com/
    HTTP/1.1 200 OK
    No loop for curl, but the chain ends on plain HTTP. A browser that has stored the site's HSTS policy goes back to HTTPS on its own and loops (Cloudflare's documentation; we did not reproduce it).Cause: The server redirects HTTPS to HTTP, Cloudflare redirects back ↓
  2. curl -sSI --resolve example.com:80:192.0.2.10 -H "X-Forwarded-Proto: https" http://example.com/ | grep -i -E "^HTTP|^location"
    If the answer isIt means
    HTTP/1.1 301 Moved Permanently
    Location: https://example.com/
    The command asks the server the way Cloudflare does in Flexible mode: plain HTTP with the header that says the visitor used HTTPS. The server redirects anyway. If the mode that applies to this name is Flexible, that is the loop.Cause: Flexible mode and a server that redirects HTTP to HTTPS ↓
    HTTP/1.1 200 OK
    The server serves this request, so its HTTP to HTTPS redirect is not the loop. Look for a redirect that matches this exact address: redirect rules and Page Rules in Cloudflare, then the application.
Terminal: curl follows five redirects, each a 301 to the same HTTPS address, and stops with Maximum (5) redirects followed
The first command on a looping name: every answer points to the address just asked.

1. Flexible mode and a server that redirects HTTP to HTTPS

The encryption mode (SSL/TLS → Overview) is Flexible, so Cloudflare always asks the server over HTTP, and the server answers every HTTP request with a redirect to HTTPS. The redirect can sit in the web server's configuration, in .htaccess, in the hosting panel (“force HTTPS”) or in the application: WordPress does it when its address is set to https:// and it does not know the visitor came over HTTPS.

How to confirm

curl -sSI --resolve example.com:80:192.0.2.10 -H "X-Forwarded-Proto: https" http://example.com/ | grep -i -E "^HTTP|^location"

The answer when this is the cause

HTTP/1.1 301 Moved Permanently
Location: https://example.com/

The command asks the server directly and adds the header Cloudflare sends for an HTTPS visitor. Our first test site still answered 301: its redirect was unconditional, and behind Cloudflare in Flexible mode it looped. The second site, which redirects only when this header is not https, answered HTTP/1.1 200 OK to the same command and worked behind Cloudflare.

How to fix it

  1. Preferred: put a certificate on the server and leave Flexible. Create an origin certificate in Cloudflare → SSL/TLS → Origin Server → Create Certificate (every plan, the Free plan included) and add it to the site's configuration on port 443.
  2. Check that the HTTPS site answers before you switch: curl -sSkI --resolve example.com:443:192.0.2.10 https://example.com/ | grep -i -E "^HTTP|^location" must end in a 200. The flag -k skips certificate validation, so this proves only that port 443 serves the site.
  3. Find the setting that gives this name Flexible: the zone's mode in SSL/TLS → Overview, or a Page Rule or configuration rule for the name (in our test it was a Page Rule). Change that one to Full (strict). Before you change the whole zone, check the other proxied names: each of them needs HTTPS on its server too.
  4. The server's redirect from HTTP to HTTPS can stay: Cloudflare now reaches the server over HTTPS and never meets it. Full (strict) validates the certificate; an origin certificate passes; a certificate that is expired, self-signed or issued for another name gives error 526, so check its dates and names first.
  5. If a certificate cannot be installed (some shared hosting), keep Flexible and make the redirect conditional: redirect only when X-Forwarded-Proto is not https. The nginx block below is the one we tested. For WordPress the documentation gives the same condition for wp-config.php: when HTTP_X_FORWARDED_PROTO contains https, set $_SERVER['HTTPS'] = 'on'.
server {
    listen 80;
    server_name example.com;

    # redirect only the visitors who came to Cloudflare over plain HTTP
    if ($http_x_forwarded_proto != "https") {
        return 301 https://$host$request_uri;
    }
    # … the site itself
}

Side effects and limits. Switching to Full before HTTPS works on the server replaces the loop with another error: in our tests 525 when port 443 answered without TLS, 521 when nothing listened on it. The conditional redirect keeps Flexible, and in Flexible mode everything between Cloudflare and your server travels unencrypted, passwords included. It also trusts a header anyone can write: in our test a direct request to the server with X-Forwarded-Proto: https was served over plain HTTP. Accept that header only from Cloudflare's address ranges, or close port 80 to everyone else.

Terminal: nginx access log lines for requests from Cloudflare in Flexible mode, port 80, X-Forwarded-Proto https, CF-Visitor scheme https, answer 301
What reached our server in Flexible mode: plain HTTP on port 80, with two headers that say the visitor used HTTPS.
Terminal: a direct request without the X-Forwarded-Proto header gets 301, the same request with the header gets 200
The conditional redirect asked directly: with the header it serves the page, without it it redirects.

2. The server redirects HTTPS to HTTP, Cloudflare redirects back

The mode is Full or Full (strict), and the server answers HTTPS requests with a redirect to http://: an old rule in .htaccess, a site address saved as http:// in the application, or a hosting plan where the HTTPS site only points to the HTTP one. On the Cloudflare side Always Use HTTPS (SSL/TLS → Edge Certificates) sends every HTTP visitor to HTTPS. Together they loop.

How to confirm

curl -sSkI --resolve example.com:443:192.0.2.10 https://example.com/ | grep -i -E "^HTTP|^location"

The answer when this is the cause

HTTP/1.1 301 Moved Permanently
Location: http://example.com/

Asked directly over HTTPS, the server sends the visitor to HTTP. In the loop we recorded, the server's log showed only the HTTPS requests: the http:// half was answered by Cloudflare and never reached the server. The flag -k skips certificate validation, so the check also works with an origin certificate.

How to fix it

  1. Find the redirect to http:// on the server and remove it: the web server's configuration, .htaccess, the application's site address (WordPress: Settings → General, both addresses must start with https://).
  2. Repeat the command: it must print HTTP/1.1 200 OK.
  3. Leave Always Use HTTPS on.

Side effects and limits. Turning Always Use HTTPS off also ends the loop, and that is the wrong fix: in our test the HTTPS address then answered with a redirect to http:// and the page was served unencrypted. Cloudflare's documentation adds that a browser which has stored the site's HSTS policy goes back to HTTPS on its own, so those visitors keep looping.

Terminal: with Always Use HTTPS off the HTTPS address redirects to HTTP and answers 200; with it on, the answers alternate between http and https
The same server before and after Always Use HTTPS was switched on.

3. Two redirects point at each other

A rule in Cloudflare sends one address to another, and a redirect on the server (or a second rule) sends it back. The common pair is www: Cloudflare redirects example.com to www.example.com, and the server or the application redirects www.example.com to example.com because that is the address saved in its settings.

How to confirm

curl -sSI https://example.com/ | grep -i -E "^HTTP|^location|^cf-cache-status"

The answer when this is the cause

HTTP/2 301 
location: https://example.com/
cf-cache-status: DYNAMIC

Run it for each of the two addresses. Every answer says server: cloudflare, so that header does not tell who made the redirect. In our test the redirect that came from the server carried cf-cache-status: DYNAMIC, and the one made by Cloudflare's own rule had no cf-cache-status line at all. In our test the redirect made by Cloudflare also left no line in the server's access log. A line there proves the request reached the server; a missing line alone does not say who made the redirect, so read the matching rules as well.

How to fix it

  1. Decide which address is the main one.
  2. In Cloudflare open the Rules section and read the redirect rules and Page Rules that match either address; delete or reverse the one that points away from the main address.
  3. On the server make the redirect point the same way: server_name and return 301 in nginx, .htaccess, or the site address in the application.
  4. Repeat the first command for both addresses: the main one answers 200, the other answers one 301 and then 200.

Side effects and limits. Keep one redirect, not zero: if both addresses answer 200 with the same content, search engines see two copies of the site.

Terminal: two names redirect to each other; the redirect from the server has the cf-cache-status header, the one from Cloudflare's rule does not
Two names pointing at each other, and the header that differed between the two redirects in our test.

What we got in eight states

Temporary names behind Cloudflare, 4 December 2026. “Loop” means curl stopped with Maximum (5) redirects followed.

CloudflareServerResult
FlexibleRedirects every HTTP request to HTTPSLoop: 301 to the same HTTPS address every time
FlexibleRedirects only when X-Forwarded-Proto is not https200; a visitor on http:// gets one 301 and then 200
Flexible switched to FullThe same redirect, plus an HTTPS site with a self-signed certificateLast 301 at 3.5 s after the switch, first 200 at 4.6 s
Full, Always Use HTTPS offHTTPS site redirects to http://, HTTP site answersNo loop: 301 to http://, then 200 over plain HTTP
Full, Always Use HTTPS onThe sameLoop: https:// → http:// → https:// …
Page Rule: example.com → www.example.comRedirects www.example.com → example.comLoop between the two names
Flexible, visitor on HTTPSLogs the request headersPort 80, X-Forwarded-Proto: https, CF-Visitor: {"scheme":"https"}
Flexible, visitor on HTTPLogs the request headersPort 80, X-Forwarded-Proto: http, CF-Visitor: {"scheme":"http"}

Our data

16.5 %

of .lt hosts that resolve answer from Cloudflare's network

17,886 of 108,195 hosts in the snapshot of 26 November 2026. For each of them the redirect to HTTPS can be made in two places, at Cloudflare and on the server, and this page is about the cases where the two disagree. The dataset records the network a host answers from, not its encryption mode, so it does not say how many of these sites run in Flexible mode or have ever looped. Dataset: Security posture of .lt websites, 26 November 2026 (CC BY 4.0)

Check that it works

Ask through Cloudflare again, for the HTTPS address and then for the http:// one.

curl -sSIL --max-redirs 5 https://example.com/ | grep -i -E "^HTTP|^location"

Expected

HTTP/2 200

For the http:// address the chain must end with a 200 on the HTTPS address you intend, without repeating an address; in our test that was one 301 and then 200. A page that requires a login may correctly end in a redirect to the login page or in 401 or 403; what matters is that the chain ends. Then open the site in a private window: a regular window may replay a 301 the browser stored while the loop was live. Check www and the bare domain separately.

Where it comes from and what it leads to

Where it comes from

  • The domain was added to Cloudflare while the server already redirected HTTP to HTTPS, and the zone's mode is Flexible.
  • “Force HTTPS” was switched on in the hosting panel or a plugin on a site that sits behind Cloudflare in Flexible mode.
  • Always Use HTTPS was switched on for a site whose server still redirects to http://.
  • A www redirect was added in Cloudflare without checking the one the server or the application already makes.

What it leads to

What to write to the hosting provider

No access to the server's configuration? For the Flexible loop, confirmed by the second command, send this to the hosting provider with your own output.

Hello,

example.com is behind Cloudflare, and visitors get ERR_TOO_MANY_REDIRECTS. A direct request to the server shows that it redirects HTTP to HTTPS on its own:

curl -sSI --resolve example.com:80:[server address] -H "X-Forwarded-Proto: https" http://example.com/
HTTP/1.1 301 Moved Permanently
Location: https://example.com/

Please do one of the following:
1. enable HTTPS for this site on port 443 (I can supply a Cloudflare origin certificate), so that I can switch Cloudflare to Full (strict) mode; or
2. make the HTTP to HTTPS redirect conditional: no redirect when the request carries the header X-Forwarded-Proto: https and comes from Cloudflare's address ranges (https://www.cloudflare.com/ips/).

Thank you.

Sources

  1. Cloudflare Docs: ERR_TOO_MANY_REDIRECTS (encryption mode, Always Use HTTPS, HSTS, redirect rules)
  2. Cloudflare Docs: Flexible mode (plain HTTP to the server, the warning about redirect loops)
  3. Cloudflare Docs: Full mode (the connection to the server uses the visitor's scheme)
  4. Cloudflare Docs: Always Use HTTPS
  5. Cloudflare Docs: HTTP headers (X-Forwarded-Proto, CF-Visitor)
  6. Cloudflare Docs: Page Rules settings (Forwarding URL, Always Use HTTPS)
  7. Cloudflare Docs: Origin CA certificates
  8. WordPress Developer Resources: HTTPS, section “Using a Reverse Proxy”
  9. RFC 9110, section 15.4.2: 301 Moved Permanently (a 301 answer may be stored by the browser)

How we tested

Tests were run on 4 December 2026: temporary sites in nginx 1.26.3 on our own server and five temporary proxied names in a live Cloudflare zone (Free plan). The encryption mode, Always Use HTTPS and the name-to-name redirect were set per name with Page Rules. Names, rules and the nginx file were deleted afterwards. Names are shown as example.com and www.example.com, the server as 192.0.2.10; every reply is unchanged. Each state was requested one to three times with curl 8 on macOS. Not reproduced, taken from documentation: a loop caused by HSTS in the browser, the WordPress setting, Apache, and Cloudflare's newer Redirect Rules (we used a Page Rule).

Next