Skip to content

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.

Trace the redirect chain

bash
# 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/   ...

Common loops and fixes

LoopWhyFix
HTTPS ↔ HTTP via CDNCDN connects to origin over HTTP ("flexible" mode); origin redirects to HTTPSUse full (strict) TLS to the origin, or trust X-Forwarded-Proto
www ↔ apexOne layer redirects to www, another to the apexPick one canonical host; remove the other rule
App behind a proxy thinks it is on HTTPFramework does not trust the proxy headersConfigure trusted proxies so the app sees https
Trailing slash rules disagreeServer adds a slash, app removes itHandle trailing slashes in one layer only
Auth redirect loopLogin page itself requires login, or a cookie is not setExclude login routes; check cookie domain and SameSite
CMS site URL settingWordPress home/siteurl differ from the real URLSet 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.

javascript
// 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)));
plaintext
# 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.

Frequently asked questions

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

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.