ERR_TOO_MANY_REDIRECTS: The Redirect Loop You Created

A redirect loop means every response says 'go somewhere else' until the browser gives up. Nine times out of ten it's HTTP→HTTPS misconfiguration in front of an origin that can't see the original scheme.

What you'll see

Root causes

Origin forces HTTPS but the proxy talks HTTP to it

The proxy connects to the origin over HTTP; the origin 301s back to https; the proxy requests again over HTTP — infinite loop. The fix is a header (X-Forwarded-Proto) the origin trusts, or proxy-level SSL to origin.

Two layers both redirecting to www (or both to apex)

Server A redirects to the name that Server B redirects back from. Trace with curl -IL and read each Location hop.

Cache poisoning of a redirect

An old 301 cached at the edge/CDN keeps applying after you fixed the config. Purge the CDN and check for stale browser cache.

Fix it

  1. Map the loop — every hop, not just the error
    curl -sIL http://example.com/ | grep -iE 'HTTP/|location'
  2. Make the origin scheme-aware via the forwarded header (nginx)
    # map $http_x_forwarded_proto $forwarded_https { default off; https on; }
    # then: if ($forwarded_https = off) { return 301 https://$host$request_uri; }
  3. Or serve the origin redirect only when the connection is actually plain
    server { listen 80; server_name example.com; return 301 https://$host$request_uri; }  # no 301 inside the 443 server block
  4. If Cloudflare is in front, match the SSL mode
    # Cloudflare 'Flexible' SSL + origin HTTPS redirect = loop. Use 'Full (strict)' with a valid origin cert.

Field note

curl -IL is the single most useful command here — it shows the entire hop chain including which layer bounces first. 301s are cached aggressively by browsers; test with curl or incognito after fixing.

Common questions

Why did this start after I enabled Cloudflare?

Cloudflare Flexible SSL fetches your origin over plain HTTP. Your origin sees HTTP and redirects to HTTPS, and the loop begins. Switch Cloudflare SSL to Full (strict) and install an origin certificate.

How do I clear a cached redirect?

Purge the CDN cache for the URL, and test in a fresh incognito window or with curl. Browser-cached 301s often outlive your patience otherwise.

Ship it right the first time

Our most-documented failures, packaged as ready-to-ship starter kits: Docker, Kubernetes, and Terraform.

Browse the template store →

One-time. Yours to modify. Instant download from the NinjaOps template store.