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.
- 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
curlor 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”.
curltold to follow redirects stops with error 47:Maximum (5) redirects followedin 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.

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.

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.
curl -sSIL --max-redirs 5 https://example.com/ | grep -i -E "^HTTP|^location"If the answer is It 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://andhttps://: 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 ↓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 is It 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.

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
- 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.
- 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-kskips certificate validation, so this proves only that port 443 serves the site. - 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.
- 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.
- If a certificate cannot be installed (some shared hosting), keep Flexible and make the redirect conditional: redirect only when
X-Forwarded-Protois nothttps. The nginx block below is the one we tested. For WordPress the documentation gives the same condition forwp-config.php: whenHTTP_X_FORWARDED_PROTOcontainshttps, 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.


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
- 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 withhttps://). - Repeat the command: it must print
HTTP/1.1 200 OK. - 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.

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: DYNAMICRun 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
- Decide which address is the main one.
- 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.
- On the server make the redirect point the same way:
server_nameandreturn 301in nginx,.htaccess, or the site address in the application. - 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.

What we got in eight states
Temporary names behind Cloudflare, 4 December 2026. “Loop” means curl stopped with Maximum (5) redirects followed.
| Cloudflare | Server | Result |
|---|---|---|
| Flexible | Redirects every HTTP request to HTTPS | Loop: 301 to the same HTTPS address every time |
| Flexible | Redirects only when X-Forwarded-Proto is not https | 200; a visitor on http:// gets one 301 and then 200 |
| Flexible switched to Full | The same redirect, plus an HTTPS site with a self-signed certificate | Last 301 at 3.5 s after the switch, first 200 at 4.6 s |
| Full, Always Use HTTPS off | HTTPS site redirects to http://, HTTP site answers | No loop: 301 to http://, then 200 over plain HTTP |
| Full, Always Use HTTPS on | The same | Loop: https:// → http:// → https:// … |
| Page Rule: example.com → www.example.com | Redirects www.example.com → example.com | Loop between the two names |
| Flexible, visitor on HTTPS | Logs the request headers | Port 80, X-Forwarded-Proto: https, CF-Visitor: {"scheme":"https"} |
| Flexible, visitor on HTTP | Logs the request headers | Port 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 200For 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
wwwredirect was added in Cloudflare without checking the one the server or the application already makes.
What it leads to
- Error 525 after switching to Full: port 443 on the server has no working TLS
- TLS certificate: the certificate expired N days ago or is valid for N more daysAn expired certificate on the server: error 526 in Full (strict) mode
- Mixed content: the page opens over HTTPS but loads its files from
http://addresses
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
- Cloudflare Docs: ERR_TOO_MANY_REDIRECTS (encryption mode, Always Use HTTPS, HSTS, redirect rules)
- Cloudflare Docs: Flexible mode (plain HTTP to the server, the warning about redirect loops)
- Cloudflare Docs: Full mode (the connection to the server uses the visitor's scheme)
- Cloudflare Docs: Always Use HTTPS
- Cloudflare Docs: HTTP headers (X-Forwarded-Proto, CF-Visitor)
- Cloudflare Docs: Page Rules settings (Forwarding URL, Always Use HTTPS)
- Cloudflare Docs: Origin CA certificates
- WordPress Developer Resources: HTTPS, section “Using a Reverse Proxy”
- 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).
