Home » Website Errors » Too Many Redirects: Find the Loop with One curl Command
Too Many Redirects: Find the Loop with One curl Command
ERR_TOO_MANY_REDIRECTS (Firefox says "The page isn't redirecting properly") means the browser was sent from URL A to URL B, and then something sent it back, over and over, until it gave up. Two rules disagree. Your job is to find which two.
Step 1: watch the loop happen
curl -sIL --max-redirs 6 https://example.com | grep -iE "^(HTTP|location)"
A loop looks like this:
HTTP/2 301
location: https://www.example.com/
HTTP/2 301
location: https://example.com/
HTTP/2 301
location: https://www.example.com/
The pair of URLs that keep swapping is your clue. Also look at the server: header on each response (drop the grep to see all headers) to learn which layer issued each redirect: a CDN, a load balancer, your web server, or the application.
Step 2: match the pattern
Pattern 1: www and non-www fight each other
Output alternates between example.com and www.example.com. One rule says "always use www", another says "never use www". Typical when a host setting and a plugin or .htaccess rule disagree. Decide which version you want and remove the other rule, in every place that issues redirects (host panel, CDN rules, server config, application).
Pattern 2: HTTP and HTTPS fight each other (Cloudflare "Flexible")
The URL alternates between http:// and https://. A classic cause: the CDN's SSL mode is "Flexible", meaning it connects to your server over plain HTTP, while your server (or a WordPress plugin) redirects every HTTP request to HTTPS. Each request the origin sees is HTTP, so it redirects forever.
Fix: install a certificate on the origin and set the CDN's SSL mode to "Full" or "Full (strict)". Keep the force-HTTPS redirect.
Pattern 3: the app does not know it is behind HTTPS
If TLS ends at a load balancer or reverse proxy, the application behind it sees plain HTTP. Frameworks and CMSs that force HTTPS then redirect endlessly. The proxy must tell the app the original scheme with X-Forwarded-Proto: https, and the app must be configured to trust it. In nginx:
proxy_set_header X-Forwarded-Proto $scheme;
Pattern 4: WordPress address settings
If the Site Address and WordPress Address (Settings, General) disagree with how the site is served, WordPress redirects to the "correct" one that then redirects back. If you cannot log in to change them, set them in wp-config.php:
define('WP_HOME', 'https://example.com');
define('WP_SITEURL', 'https://example.com');
Then check that no redirect plugin or .htaccess rule says the opposite.
Pattern 5: path-based loop
The URL stays on one host but alternates between paths (/login and /). Usually an application rule: a login redirect where the session cookie is not being kept, or a trailing-slash rule fighting a rewrite rule.
Step 3: confirm the fix
Run the same curl command. A healthy site shows at most one or two redirects (for example http to https) ending in a 200:
HTTP/2 301
location: https://example.com/
HTTP/2 200
Then test in a private window to avoid a cached redirect, since browsers cache 301 responses firmly.
Common mistakes
- Adding a new redirect rule on top of the old one instead of replacing it.
- Fixing the server while a CDN page rule or redirect rule still loops.
- Testing only in a normal browser window that remembers the old permanent redirect.
- Changing several things at once, so you cannot tell which one fixed it. Change one, test, repeat.
If HTTPS itself is failing rather than looping, see HTTPS not working.
Frequently Asked Questions
Should I clear cookies first?
It is a quick test and sometimes helps when a login or language cookie causes the loop. If the loop also happens in a private window or from curl, the cause is the server or CDN, not your browser.
Why does the loop only happen on HTTPS?
Usually because one layer forces HTTPS while another layer talks to your server over plain HTTP, so the server keeps redirecting a request it believes is insecure.
How many redirects will a browser follow?
Chrome gives up at 20 redirects, and other browsers have similar limits. A loop never ends, so it always hits the limit.
Found a mistake or still stuck? Contact us. See how we write and check these guides in our editorial policy, or read about DocumentGuy.