Fixing a Redirect Loop Between Cloudflare and Your Host (ERR_TOO_MANY_REDIRECTS)
Why a site starts throwing ERR_TOO_MANY_REDIRECTS the moment Cloudflare is switched on, how to find which side is redirecting, and the settings and server rules that end the loop.
The site worked yesterday. You moved the DNS to Cloudflare, turned on the orange cloud, and now every browser says “This page isn’t working: redirected you too many times.” Nothing on the server changed, which is exactly why it is confusing.
What changed is that there are now two machines making decisions about HTTP and HTTPS: Cloudflare at the edge and your host at the origin. If they disagree, each one keeps sending the visitor back to the other. The browser gives up after a set number of hops and shows ERR_TOO_MANY_REDIRECTS.
The fix is almost always one setting or one rule. Finding which one is the real work.
The most common cause: Flexible mode plus an HTTPS redirect on the server
Cloudflare has a setting for how it connects to your server, called the encryption mode. In Flexible mode, the visitor talks to Cloudflare over HTTPS, but Cloudflare talks to your server over plain HTTP.
Now suppose your server has a rule that says “any HTTP request, redirect to HTTPS”. Most hosts add one by default, and most .htaccess files have one. Here is what happens:
- The browser requests
https://example.com/. - Cloudflare fetches
http://example.com/from your server. - Your server sees HTTP and replies with a 301 to
https://example.com/. - Cloudflare passes that redirect back to the browser.
- The browser requests
https://example.com/again. Back to step 2.
Your server never sees the HTTPS request, because Cloudflare never sends one. Cloudflare’s own troubleshooting page lists this as the first cause and gives two fixes: remove the HTTPS redirect from the origin, or move the encryption mode to Full or higher, which needs a certificate on your server.
Take the second option. Flexible mode means the leg between Cloudflare and your host is unencrypted, and Cloudflare’s documentation recommends Full or Full (strict) for that reason.
Full (strict) is the setting you want
In Full mode, Cloudflare connects to your server using the same protocol the visitor used, so an HTTPS visit reaches your server as HTTPS and the server’s redirect rule stays quiet. Full (strict) does the same but also checks that your server’s certificate is valid.
Your server needs a certificate for this. Two easy routes:
- Most hosts (cPanel, hPanel, Plesk) issue a free Let’s Encrypt certificate from the control panel.
- Cloudflare can issue an Origin CA certificate that you install on the server. Browsers do not trust it directly, but Cloudflare accepts it in Full (strict) mode, and visitors only ever see Cloudflare’s edge certificate.
Then go to SSL/TLS in the Cloudflare dashboard. Newer zones show an “Automatic SSL/TLS” option that picks the most secure mode it can verify your server supports. If your zone shows the custom options instead, choose Full (strict).
The other direction: Full mode and a server that forces HTTP
Less common, but it happens on older sites. The encryption mode is Full, so Cloudflare sends HTTPS to the server, and something on the server redirects HTTPS back to HTTP. Usually it is a leftover rule from before the site had a certificate, or a CMS whose site address is still saved as http://.
On WordPress, check Settings, General. Both address fields should start with https://. If they do not and you cannot log in because of the loop, set them in wp-config.php:
define('WP_HOME', 'https://example.com');
define('WP_SITEURL', 'https://example.com');
Then search .htaccess for any rule whose target begins with http:// and remove it.
Two redirect rules fighting over www
The third pattern has nothing to do with SSL. Cloudflare has a redirect rule (or an old Page Rule) sending www.example.com to example.com, while the server sends example.com to www.example.com. Each does its job perfectly and the visitor bounces between them forever.
Decide which hostname is canonical and redirect in one place only. We prefer Cloudflare for this, because the redirect happens at the edge before the request ever reaches your host. If you keep it on the server instead, delete the Cloudflare rule. The .htaccess redirect guide covers the one-hop server version.
How to see which side is redirecting
Guessing wastes time. curl shows each hop without the browser’s cache getting in the way:
# Follow the chain through Cloudflare, headers only, stop after 5 hops
curl -sIL --max-redirs 5 https://example.com/ | grep -iE "^(HTTP|location|server)"
If every response shows the same location pointing at the URL you just requested, you have a loop. The server: cloudflare line only confirms the proxy is in the path, not who issued the redirect. To find that out, ask the origin directly, skipping Cloudflare, by pinning the domain to your server’s IP:
# Replace 203.0.113.10 with your host's server IP
curl -sI --resolve example.com:443:203.0.113.10 https://example.com/
curl -sI --resolve example.com:80:203.0.113.10 http://example.com/
If the server answers HTTPS with a 200 and HTTP with a 301 to HTTPS, it is behaving correctly and the problem is the Cloudflare mode or a Cloudflare rule. If the server redirects HTTPS somewhere unexpected, the problem is on the host. (With Full (strict) and an Origin CA certificate, add -k to the first command, since curl does not trust that certificate.)
Test in a private window after each change. Browsers cache 301 redirects, so a normal tab can keep showing the loop after you have fixed it.
When you cannot change the encryption mode yet
Sometimes the server has no certificate and you need the site back up today. Cloudflare tells the origin what protocol the visitor used, through the X-Forwarded-Proto header (and CF-Visitor, which carries the same scheme as JSON). You can make the server’s redirect respect it:
RewriteEngine On
# Only redirect when neither the server nor Cloudflare saw HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
Treat this as a stopgap. The Cloudflare to server leg is still unencrypted, and anything that can reach your server directly can send that header. Install a certificate and switch to Full (strict) as soon as you can.
The cleaner long-term setup: turn on Always Use HTTPS in Cloudflare and remove the HTTP to HTTPS rule from the server. Cloudflare’s documentation advises against redirecting at the origin for this reason. Combined with Full (strict), you get one redirect, at the edge, and nothing for the two sides to argue about.
Quick reference
| Symptom | Likely cause | Fix |
|---|---|---|
| Loop right after enabling the proxy | Flexible mode, server forces HTTPS | Certificate on server, Full (strict) |
| Loop after switching to Full | Server or CMS forces HTTP | Update site URL, remove http:// rules |
| Loop only on www or only on apex | Cloudflare rule and server rule disagree | Keep one canonical redirect, in one place |
| Fixed, but your browser still loops | Cached 301 | Test in a private window |
If your site sits on a mix of Cloudflare, shared hosting and old redirect rules nobody remembers adding, this kind of conflict tends to come back. We audit and rebuild that layer as part of our web systems work. If you want the stack checked or a migration done without the downtime, request a quote.