Skip to the content
All posts

Redirects3 min read

Redirect chains and loops: where they come from and how to find them

Every migration leaves redirects behind, and they pile up. How chains and loops form, why they matter, and a routine for keeping them short.

A redirect is a promise: the page you asked for lives somewhere else now. One redirect is cheap and correct. The trouble is what happens after a site has moved a few times.

How chains form

Each move adds a rule for the address that was current at the time. Nobody goes back to the older rules, so they stack.

Three migrations later
http://example.com/shop/item-42
  301 -> https://example.com/shop/item-42
  301 -> https://www.example.com/shop/item-42
  301 -> https://www.example.com/products/item-42
  200

Every step is reasonable on its own: a move to HTTPS, a move to www, a new URL structure. Together they make three round trips before the first byte of the page.

How loops form

A loop needs two rules that disagree. One layer adds a trailing slash and another removes it. The application redirects to www and the edge redirects away from it. An old rule sends A to B, and a new one sends B back to A.

A browser gives up and shows an error. A crawler gives up too, and the page behind the loop can no longer be reached by anyone.

Why they matter

  • Speed. Each hop is a full request and response. On a phone connection that is easy to feel.
  • Crawling. Crawlers follow only so many hops before they stop. Google documents a limit of ten; others are stricter.
  • Mixed signals. A chain with a temporary redirect in the middle tells search engines to keep the old address, so the new one is slow to take its place.
  • Fragility. A chain breaks when any one of its rules is removed, and old rules are the first to go in a cleanup.

Keeping them short

  1. Follow every redirect to its end. Record each hop and its status code, not only where it lands.
  2. Rewrite old rules. When an address moves again, update the earlier rules to point at the new final address.
  3. Fix your own links. A link on your site that goes through a redirect is a hop you control. Link to the destination.
  4. Check after each release. Rules live in several layers (the app, the host, the edge), and a change in one can form a loop with another.
Following a chain by hand
curl -sIL http://example.com/shop/item-42 | grep -iE '^(HTTP|location)'

With Ranky

Ranky follows every redirect it meets while crawling. It reports a chain of two or more hops, a loop, a redirect that ends on an error, and an internal link that leads to a temporary redirect. As with every issue, a chain that a deploy created is reported with that deploy.

More in Checks and Getting started.

Catch the next bad deploy before search engines do

Start with one site, free. Every check, weekly scans, no card needed.