Article
HTTPS redirect loop: why a site redirects to itself forever
Published 2026-11-28
HTTPS redirect loop: why a site redirects to itself forever
You enabled HTTPS, added the redirect, and now the site bounces a request between two URLs until the browser gives up with ERR_TOO_MANY_REDIRECTS. The page never loads. Nothing crashed. From the server's point of view every redirect was correct, which is exactly why these loops are confusing: each hop looks right on its own, and the loop only exists once you see them in sequence.
A redirect loop is not a redirect problem. It is a visibility problem: somewhere in the chain, a component cannot see what the visitor actually asked for, so it "corrects" a request that did not need correcting. This article covers the four loop shapes you will actually meet, how to see your loop with curl instead of guessing, and the fix for each.
The tool that shows you the loop
Browsers hide the chain and show only the final error, so diagnose with curl first:
curl -sIL --max-redirs 8 https://example.com | grep -iE '^(HTTP|location)'
-I fetches headers, -L follows redirects, and --max-redirs 8 stops the loop before curl loops with it. The output tells you which of the four shapes you have:
HTTP/2 301
location: https://example.com/
HTTP/2 301
location: https://https://example.com/ (a mangled scheme in the target URL)
HTTP/2 301
location: https://https://example.com/https://https://example.com/
A URL redirecting to itself means the server cannot tell the visitor already used HTTPS. Two URLs taking turns, www against bare domain, means two rules disagree about the canonical address. Read the Location headers and you have your diagnosis before touching a single config file. One more note that saves an hour later: browsers remember 301s. An old loop cached by the browser will keep happening after you fix the server, so test with a private window or curl after every change.
Loop shape 1: Cloudflare (or any proxy) on Flexible SSL
The classic. You put the site behind Cloudflare, and it breaks the moment you also redirect HTTP to HTTPS at the origin. The mechanics:
- The visitor asks Cloudflare for
https://example.com. - Cloudflare, in Flexible mode, asks your server for
http://example.comover plain HTTP. - Your server sees an HTTP request and answers
301 https://example.com. - The visitor asks for
https://example.comagain. Back to step 1.
The origin never learns the visitor used HTTPS, because Cloudflare never told it. Flexible mode is also worth leaving for a reason unrelated to loops: the segment between Cloudflare and your server is unencrypted, so the "HTTPS" badge is only half the picture.
The fix has two parts, and both are needed. Install a certificate on the origin (a free Cloudflare Origin CA certificate or Let's Encrypt both work), then set SSL/TLS to Full (strict). While you are in there, check Rules for any "Always Use HTTPS" or redirect rules that might fight with the origin's own redirect; two enforcers in two places is how the next loop starts.
Loop shape 2: the redirect inside the HTTPS server block
A pure nginx mistake, usually made right after adding a certificate. One server block listens on both ports and redirects everything:
# WRONG — this redirects HTTPS requests back into HTTPS
server {
listen 80;
listen 443 ssl;
server_name example.com;
return 301 https://example.com$request_uri;
}
The block that serves HTTPS also redirects it, so a request arrives on 443 and is immediately told to go to 443 again. The fix is to separate the ports:
server {
listen 80;
server_name example.com;
return 301 https://example.com$request_uri;
}
server {
listen 443 ssl;
server_name example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
# ... your actual site config
}
The redirect lives only in the block that serves port 80, and the 443 block serves content instead of opinions. After any nginx edit: sudo nginx -t && sudo systemctl reload nginx, then re-run the curl check. You want one or two redirects at most, ending in 200.
The same shape appears behind a reverse proxy: an HTTPS front terminates TLS and hands the app an HTTP request on 127.0.0.1, the app decides the request is insecure and redirects, and the proxy forwards it again. The proxy must forward what the visitor actually used:
proxy_set_header X-Forwarded-Proto $scheme;
and the app must be configured to trust that header only when it really is behind that proxy, because a client that reaches the app directly can forge it. Symfony, Laravel, and Django all have a "trusted proxies" setting that gates this on purpose.
Loop shape 3: two rules fighting over www
This one has no certificate involved at all: nginx says "go to www", and the application (or a proxy rule, or a Cloudflare rule) says "go to bare domain", so the request ping-pongs forever:
location: https://www.example.com/
location: https://example.com/
location: https://www.example.com/
The fix is to pick one canonical address and let only one component own the redirect. If bare domain wins, nginx handles the www side:
server {
listen 443 ssl;
server_name www.example.com;
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/redirect.key.pem;
return 301 https://example.com$request_uri;
}
Then make the application agree, because if WordPress siteurl or home options, a Laravel APP_URL, or Django ALLOWED_HOSTS disagree with nginx, the fight resumes at the application layer. In WordPress check with wp option get siteurl and wp option get home; if the database says http:// while the web server redirects to https://, you have built this loop even without a proxy anywhere. WordPress also has a well-documented RELOCATE dance for when the options point at a stale URL after a migration, and using wp-cli beats editing the database by hand.
Loop shape 4: the app redirecting everything, including the login form
The subtlest of the four, because the loop appears only after some application-level force-HTTPS setting is switched on. WordPress's FORCE_SSL_ADMIN or a plugin that redirects every request sees an HTTP request on the inside of a proxy and redirects; the proxy forwards; the app redirects again. The difference from shape 2 is that nothing is wrong with nginx here. The proxy is already forwarding X-Forwarded-Proto, and the app is just not honoring it. In WordPress the check is whether the server passes the header and whether the app trusts it. Some hosts do this correctly out of the box and some pass nothing, so:
curl -sI http://example.com/wp-login.php | head -5
should answer with a redirect to the https version, not a loop of redirects to itself. If wp-login.php loops, the app is issuing its redirect without seeing the original scheme, and the host-level X-Forwarded-Proto header is the thing to confirm with whoever controls the proxy layer. While you are in that config, read the header name letter by letter. It is X-Forwarded-Proto, one r in "Forwarded", and I have seen the two-r spelling survive in a production config for weeks because everything else around it was correct. An app checking a header nobody sends will decide every request is HTTP and redirect everything, perfectly looping. Some setups also keep reproducing an old loop from browser cache after the fix is live, so clear cookies and test in a private window before concluding the fix failed.
Questions people ask
What does ERR_TOO_MANY_REDIRECTS mean?
The browser followed the maximum number of redirects (usually 20) without ever reaching a page that returns 200, almost always because two components each try to redirect the same request in conflicting directions.
How do I fix too many redirects in WordPress?
Check that siteurl and home use the same scheme and host the site actually serves, then look at any force-HTTPS plugin: behind Cloudflare Flexible SSL or a proxy that does not pass X-Forwarded-Proto, those plugins redirect their own requests in a loop.
Why does my site loop only behind Cloudflare?
Flexible SSL mode asks your server over plain HTTP, so your HTTPS redirect sends the request back to Cloudflare over and over. Install an origin certificate and switch the mode to Full (strict).
Can a redirect loop be caused by cookies?
Yes. Browsers cache 301 responses and serve them locally, and cached cookies from an old misconfiguration can keep the loop alive after the server is fixed. Test in a private window to tell cache apart from config.
Redirect loops are a perimeter visibility problem, and the perimeter is exactly what the free scan on this site looks at. If you are untangling one after moving behind a CDN or proxy, run a scan and see the headers, TLS posture, and redirect chain your site actually presents to visitors before any more config changes.