Troubleshooting guide
ERR_TOO_MANY_REDIRECTS: how to fix a redirect loop
Browsers give up after about 20 redirects. A loop almost always comes from two layers disagreeing about HTTPS or the canonical hostname.
3 min read9 sectionsUpdated
On this page
Key points
- Trace the chain with curl to see exactly which URLs bounce.
- The classic loop: the CDN talks HTTP to the origin, and the origin redirects to HTTPS, forever.
- Decide each rule in one place: HTTPS, www or apex, trailing slash.
- Monitor key URLs with redirects followed, so a loop fails a check immediately.
# Follow up to 10 redirects and print each hop's status and Location
curl -sIL --max-redirs 10 https://example.com/ | grep -iE '^(HTTP|location)'
# Example of a loop:
# HTTP/2 301 location: https://www.example.com/
# HTTP/2 301 location: https://example.com/
# HTTP/2 301 location: https://www.example.com/ ...| Loop | Why | Fix |
|---|---|---|
| HTTPS ↔ HTTP via CDN | CDN connects to origin over HTTP ("flexible" mode); origin redirects to HTTPS | Use full (strict) TLS to the origin, or trust X-Forwarded-Proto |
| www ↔ apex | One layer redirects to www, another to the apex | Pick one canonical host; remove the other rule |
| App behind a proxy thinks it is on HTTP | Framework does not trust the proxy headers | Configure trusted proxies so the app sees https |
| Trailing slash rules disagree | Server adds a slash, app removes it | Handle trailing slashes in one layer only |
| Auth redirect loop | Login page itself requires login, or a cookie is not set | Exclude login routes; check cookie domain and SameSite |
| CMS site URL setting | WordPress home/siteurl differ from the real URL | Set both to the canonical https URL |
Trusting proxy headers
When TLS ends at a load balancer or CDN, your app receives plain HTTP and must read X-Forwarded-Proto to know the visitor used HTTPS. If it does not, an "always redirect to HTTPS" rule fires on every request.
// Express: trust the first proxy so req.secure reflects X-Forwarded-Proto
app.set('trust proxy', 1);
app.use((req, res, next) => (req.secure ? next() : res.redirect(301, 'https://' + req.headers.host + req.url)));# Nginx behind a TLS-terminating load balancer
if ($http_x_forwarded_proto = "http") {
return 301 https://$host$request_uri;
}Preventing loops
- Document where each rule lives: CDN, load balancer, web server or app.
- Test after DNS, CDN or TLS changes with the curl trace above.
- Monitor the canonical URLs with an HTTP check that follows redirects and expects a 200 and some known text.
For SEO-friendly redirect rules, see redirects done right.
Why does clearing cookies sometimes fix it?
Some loops depend on a cookie, such as a stale login or language cookie. Clearing it breaks the loop for that visitor but not for others; fix the rule.
How many redirects are acceptable?
One is ideal. Chains of two or three slow down every visit and waste crawl budget. Link directly to the final URL.
Check it now, free
- Redirect checker: Trace every 301, 302 and 307 hop to the final URL.
Related reading
- Cloudflare error 1015 "You are being rate limited": how to fix it: Fix Cloudflare error 1015 "You are being rate limited": what triggers rate limiting rules, how long blocks last, and how site owners tune them.
- Nginx "worker_connections are not enough": how to fix it: Fix Nginx worker_connections are not enough: why proxying uses two connections per client, how to size limits, raise descriptors and add upstream keepalive.
- PostgreSQL "too many clients already": how to fix it: Fix PostgreSQL FATAL: sorry, too many clients already. See who holds connections, stop leaks, add PgBouncer and size max_connections the right way.
- ERR_ADDRESS_UNREACHABLE: how to fix it: Fix ERR_ADDRESS_UNREACHABLE: no route to the server, wrong IP in DNS, IPv6 problems, private addresses and firewalls, for visitors and server owners.
- ERR_INTERNET_DISCONNECTED: how to fix it: Fix ERR_INTERNET_DISCONNECTED in Chrome: reconnect Wi-Fi, check the router, disable proxies and VPNs, reset network settings, and when apps say offline.
- Cloudflare error 1016 "Origin DNS error": how to fix it: Fix Cloudflare error 1016 Origin DNS error: CNAME records pointing to names that do not resolve, deleted origins and load balancer pools, with checks.
Watch your own site and services with VitalRix
Uptime checks, APM, logs, real-user monitoring, alerts and status pages in one place. Every product has a free tier and no credit card is needed.