A redirect loop happens when navigation keeps sending a visitor to another URL without reaching the intended page. Browsers may show ERR_TOO_MANY_REDIRECTS or a similar error. To fix it, capture the response sequence, find the rules that disagree, and make every supported entry URL reach one stable destination.
This guide is for developers and students who control a website's hosting or application configuration. If you are visiting someone else's site, a fresh browser session can help identify a local state problem, but only the site owner can repair conflicting server rules.
Redirect loop troubleshooting checklist
Keep a small record before changing configuration:
- Save the starting URL, request time, browser error, and affected release.
- Capture each HTTP status and
Locationvalue with a bounded GET request. - Compare scheme, hostname, path, query parameters, and session requirements at each step.
- Identify which CDN, proxy, router, or authentication rule owns each redirect.
- Repair the conflicting rule and test both the alternate URL and final destination.
- Repeat in a fresh browser and the previously failing session, then retain the result in CI.
Avoid changing several redirect layers together. A single reviewed change is easier to verify and reverse if the route still fails.
Distinguish a redirect loop from a long chain
HTTP redirects commonly use a 3xx response and a Location header. A chain terminates at a resource; a loop does not. MDN's HTTP redirection guide explains server redirects, HTML refreshes, JavaScript navigation, and loops caused by conflicting mechanisms.
For example, these two rules disagree:
https://example.com/docs → https://www.example.com/docs
https://www.example.com/docs → https://example.com/docs
A loop can also repeatedly redirect to the same visible URL, or keep appending a query parameter so no complete URL repeats. A redirect-limit error establishes that the client stopped following responses. Inspect the sequence before concluding that a particular pair of rules caused it.
For deliberate URL moves and canonical selection, use the canonical URLs and redirects guide. Here, the immediate objective is a destination that actually serves the intended page.
Trace the redirect loop with curl and DevTools
Start with one response, without following it:
curl --silent --show-error --max-time 20 \
--dump-header - --output /dev/null \
'https://example.com/docs'
Then follow a bounded sequence and save all response headers:
curl --silent --show-error --location --max-redirs 8 \
--max-time 30 --dump-header /tmp/redirect-headers.txt \
--output /dev/null \
--write-out 'status=%{http_code} final=%{url_effective} redirects=%{num_redirects}\n' \
'https://example.com/docs'
Read the header file in order. Record the status, Location, cache headers, and any request ID beside each requested URL. A relative Location must be resolved against the URL that returned it. The curl manual documents redirect following, redirect limits, and write-out fields. These examples use GET because a HEAD handler may behave differently.
If curl stops at its redirect limit, preserve its error and exit status. Do not treat the last printed status as a successful final response. Avoid sharing raw headers containing session cookies or other secrets.
In browser DevTools, open Network, preserve the log, and reproduce the navigation. If curl gets HTML but the browser keeps navigating, inspect the document's refresh metadata and application navigation code. Compare a fresh session with the failing session. Different results narrow the investigation to browser state or client behavior; they do not establish that the deployment is healthy for every visitor.
Fix conflicting HTTPS, hostname, and slash rules
List the intended final scheme, host, and path for the failing route. Then inspect redirect configuration at every layer that can answer that request: CDN rules, load balancer, web server, framework middleware, and application router.
Common conflicts include:
- The CDN sends the bare domain to
www, while the application sendswwwback. - The server adds a trailing slash, while the framework removes it.
- An old route sends visitors to a new route that still points back to the old route.
- An HTTPS request reaches an application over an internal HTTP connection, and the application repeatedly requests HTTPS at the public URL.
For each transformation, choose an owner and make the destination exempt from that transformation. Test the already-canonical URL directly: it should serve the page without redirecting again. Preserve meaningful paths and query parameters according to the route contract.
Cloudflare documents a specific Flexible encryption redirect loop: its HTTP connection to an origin can conflict with an origin rule requiring HTTPS. Configure origin TLS correctly and choose an appropriate end-to-end encryption mode. Inspect both ends of the connection before changing settings.
For other reverse proxies, follow the framework's trusted-proxy configuration so it can interpret the original scheme correctly. Accept forwarded scheme information only from trusted infrastructure. Do not make arbitrary incoming headers authoritative or weaken TLS to hide the symptom.
Once the route works, update links and sitemap entries to use its final URL. Google's redirect guidance distinguishes permanent moves using 301 or 308 from temporary moves using 302 or 307. Changing the status alone does not repair conflicting destinations.
Diagnose login loops and stale browser state
If /account sends a visitor to /login and /login immediately sends them back, trace the session decision on both routes. Compare what the callback sets with what the protected route reads.
Check cookie domain, path, Secure and SameSite settings against the actual deployment. Inspect whether the browser accepted the cookie and sent it on the next relevant request. Use MDN's Set-Cookie reference for attribute behavior. Keep cookie values and authentication codes out of incident notes.
Test signed-out, valid-session, and expired-session cases in an environment you control. Ensure the login route and required callback can complete without being redirected through the same authentication guard. Validate return destinations using an explicit allowlist or same-origin policy.
Clearing cookies may change the symptom, but visitors with existing sessions still need a working path. Likewise, compare fresh and previously used browser profiles after a redirect repair. Inspect cached redirect responses, CDN rules, and service worker behavior before purging caches broadly. The Cache-Control header guide explains how to separate stale delivery from a current deployment problem.
Add HTTP redirect testing to CI
Write a contract for a route you own. This Playwright example expects /old-docs to return one permanent redirect to /docs, and /docs to return HTML without another HTTP redirect. Replace the URLs, status, and heading with your deployment's contract.
import { test, expect } from "@playwright/test";
test("old documentation reaches one stable public page", async ({ request, page }) => {
const oldUrl = "https://example.com/old-docs";
const finalUrl = "https://example.com/docs";
const redirect = await request.get(oldUrl, { maxRedirects: 0 });
expect(redirect.status()).toBe(308);
const location = redirect.headers()["location"];
expect(location).toBeTruthy();
expect(new URL(location!, oldUrl).href).toBe(finalUrl);
const destination = await request.get(finalUrl, { maxRedirects: 0 });
expect(destination.status()).toBe(200);
expect(destination.headers()["content-type"]).toMatch(/^text\/html\b/i);
await page.goto(oldUrl);
await expect(page).toHaveURL(finalUrl);
await expect(page.getByRole("heading", { level: 1, name: "Documentation" }))
.toBeVisible();
});
Playwright's APIRequestContext documentation defines maxRedirects: 0 as disabling automatic redirect following. Inspecting both responses prevents a successful final request from concealing an unexpected intermediate redirect. The browser assertion also checks the rendered destination, but a single test does not exercise every later client-side navigation.
Add separate cases for HTTP entry, alternate hostname, slash variants, and session states that your site supports. Use the navigation testing checklist to select important routes and the website regression testing guide to retain a reviewable baseline. Run against the deployed candidate after the relevant CDN and application rules are active.
Verify the recovered public URL with Slop Audit
After repairing the loop, run a Slop Audit on the public entry URL. Its static fetch follows at most five redirects. When the page is reachable, redirect integrity evidence records the redirect count and final URL, and flags longer or cross-origin chains for review. A redirect-limit fetch failure is reported as a reachability failure; it does not prove which configuration rule caused it.
Use that report alongside your saved response sequence to check the recovered page's metadata and surrounding launch readiness. An intentional host change can still produce a warning that needs interpretation. Slop Audit does not inspect private proxy configuration, authenticate through login flows, or diagnose every JavaScript redirect. Keep your route and session tests as release evidence, then rescan after future routing changes.