Skip to the indexed answers
Digital Marketing Index

usdigitalmarketingindex.com SEO

How can redirect loops be detected before a redesigned website launches?

By requesting every URL that should redirect, following each redirect hop by hop with a client that records the path, and flagging any path that revisits a URL it has already seen. A loop is a redirect sequence that returns to its own start: A sends to B, and B sends back to A. It never ends, so the page never loads. A browser gives up with an error, and a crawler abandons the URL. That makes a loop different in kind from a long chain, which is slow but arrives. Loops are created by rules that each look correct alone and conflict together, which is why they appear at launch, when new rules meet old ones. Testing the full set of URLs against the staging environment, across every protocol and host variant, finds them while they are still harmless.

Loop patterns

An A-to-B-to-A example:

Request:  http://example.com/services
  301 ->  https://example.com/services        (rule 1: force HTTPS)
  301 ->  https://example.com/services/       (rule 2: add trailing slash)
  301 ->  https://example.com/services        (rule 3: new CMS removes trailing slash)
  301 ->  https://example.com/services/       (rule 2 again)
  ...     never resolves

Rules 2 and 3 are each reasonable. Together they bounce the URL between two forms.

Patterns that produce loops:

Pattern Mechanism
Trailing slash conflict The server adds the slash; the application removes it
www conflict One layer redirects to www; another redirects to the bare domain
HTTPS conflict The origin redirects to HTTPS; a proxy in front connects to the origin over HTTP, so the origin redirects again
Case conflict One rule lowercases; another redirects to a mixed-case canonical
Old map meets new map The legacy redirect file sends X to Y; the new migration map sends Y to X
Self-redirect A rule's pattern matches its own target
Language or location redirect The site redirects to a locale path; the locale path redirects back for visitors without a cookie
Login or consent redirect A page redirects to a gate; the gate redirects back when a cookie cannot be set
Canonicalizing parameters A rule strips a parameter that another rule adds
Longer cycles A to B to C to A, across three rule sets

Loops can be conditional. Some occur only without cookies, only for a certain user agent, only over HTTP, or only on a particular host variant. A test from a logged-in browser on the preferred URL can miss them all.

Crawler and HTTP client tests

Test at two levels: the complete list by script, and samples by hand.

The URL list for testing:

  • every old URL in the redirect map;
  • every new URL, which should return 200 with no redirect;
  • each of those in every variant: http and https, www and bare, with and without trailing slash;
  • a sample with uppercase letters and with query parameters;
  • non-page resources that are being moved.

Validation sequence for each URL:

1. Request the URL. Do not follow redirects automatically.
2. Record: status code, Location header.
3. If the status is a redirect:
     a. Resolve the Location to an absolute URL.
     b. If that URL is already in this request's path -> LOOP. Stop. Flag.
     c. If the path has reached the hop limit (for example 10) -> flag as
        loop-or-excessive-chain. Stop.
     d. Otherwise add it to the path and go to step 1 with the new URL.
4. If the status is not a redirect: record the final status and the hop count.

A command-line check for one URL, limiting redirects so that a loop ends in an error instead of hanging:

curl -sIL --max-redirs 10 -o /dev/null -w "%{http_code} %{num_redirects} %{url_effective}n" "http://example.com/services"

A loop shows as an error about the maximum number of redirects being exceeded. Run the same test without cookies, since a default client holds none, and that is the condition a crawler is in.

Other tools:

Tool Use
Site crawler in list mode Upload the URL list; report redirect chains and loops for each
Site crawler in spider mode Crawl staging from the home page; report any internal link leading into a loop
Browser developer tools Reproduce a flagged loop and see each hop
Server logs on staging A burst of repeated requests for two alternating URLs from one client

Test from outside the staging network where possible, through the same CDN and proxy layers that production will use. A loop created between a CDN and an origin does not exist when the origin is tested directly.

Root cause in server rules

A loop is the product of at least two rules. Find both.

Redirects can be issued at several layers, in the order a request passes through them:

Layer Examples of rules
DNS or domain forwarding Registrar-level forwarding
CDN or edge HTTPS enforcement, host normalization, page rules
Load balancer or reverse proxy Protocol and host redirects
Web server configuration Rewrite rules, slash handling
Application or CMS Canonical URL enforcement, permalink redirects
Plugins Redirect managers, SEO plugins, language plugins
Page-level Meta refresh, JavaScript redirects

Method:

  1. Take the flagged path and note each hop’s status and target.
  2. For each hop, identify which layer issued it. Response headers that name the server, or differ between layers, help. Disabling layers one at a time on staging is the reliable way.
  3. State the two rules in words: “Layer A insists on X; layer B insists on not-X.”
  4. Decide which form is canonical. Change the other rule to agree, or remove it.
  5. Retest the URL and the whole list, since changing a rule can create a loop elsewhere.

Give each normalization one owner. Protocol, host, trailing slash, and case should each be decided at a single layer, and the others configured to accept the result. Two layers enforcing the same thing agree until the day one of them is changed.

For the HTTPS proxy case, the fix is for the origin to learn the original protocol from the proxy’s forwarded header, or for the proxy to connect to the origin over HTTPS.

Release block criteria

Make the redirect test a gate that the launch must pass.

Criterion Threshold If failed
Loops in the redirect map URL list Zero Launch blocked
Loops on any host or protocol variant of the home page and top templates Zero Launch blocked
Loops reachable from internal links in a staging crawl Zero Launch blocked
URLs exceeding the hop limit Zero Launch blocked until explained
Old URLs ending in an error instead of the mapped target Zero for priority URLs; a reviewed list for others Fix or accept by sign-off
New URLs that redirect Zero Fix
Chains longer than one hop Reported Fix where practical; not a block
Test run through production-equivalent layers Done Launch blocked until done
Test run without cookies Done Launch blocked until done

A loop is a block and not a warning because it takes a page offline for everyone. There is no partial failure.

After launch, run the identical test against production straight away. Staging and production differ in certificates, CDN settings, and environment variables, and those differences are where a loop that staging never showed can come from. Keep the URL list and the script, and run them after every later change to redirect rules.

In Search Console, pages caught in a loop are reported under redirect errors in the page indexing report, whose help page lists a redirect loop among those errors (Search Console Help on the page indexing report). That report is a confirmation after the fact. The test above is what prevents the entry.

Chains that do end, and what their length costs, are a separate subject, covered in the guide to how multi-hop redirects affect search crawler efficiency.

The rule: follow every redirect to its end before launch, on every variant, without cookies, through the real layers, and release nothing while any path comes back to where it started.

Link trail

Reader comments on this answer

Add your comment to this answer

Your email address will not be published. Required fields are marked *