Skip to content

Auditing a redirect chain with curl: one hop maximum to the final URL

Every entry URL should reach its final 200 in at most one redirect. Here is the curl method to measure hops, attribute each one to Cloudflare, the origin, or the CMS, and collapse the common three-hop chains.

The working standard for a healthy site: any URL a visitor can enter — old bookmark, ad click, bare domain typed by hand — reaches its final 200 in at most one redirect. Every extra hop is a full round trip before the page even starts loading, another URL for crawlers to track, and another chance to drop a query string. Curl measures this in seconds, because unlike a browser it has no cache and no HSTS memory: it reports what the network actually does today.

What’s happening

Each hop in a chain has an issuer, and the issuers answer in a fixed order: the Cloudflare edge first — Always Use HTTPS, then Bulk Redirects, then Single Redirects, then any legacy Page Rules (only on proxied hostnames); the origin server next; the CMS last. Browsers add a fourth issuer in front — their own cache of past 301s — which is exactly why the audit must run in curl, where that layer does not exist.

Chains accumulate one owner at a time. The classic three-hop specimen: Always Use HTTPS upgrades the scheme (http://example.com to https://example.com), a host rule moves to www (https://www.example.com), and the CMS adds a trailing slash. Each hop was individually reasonable; nobody owns the sum. Legacy content moves stack a fourth hop on top when an old bulk-redirect entry points at a URL that has since been canonicalized again.

What to check first

  • The entry surface. At minimum: the four scheme and host variants of the domain. Realistically, add the top landing paths from analytics and any legacy URLs that still receive traffic (old campaigns, retired slugs).
  • The declared final form — scheme, host, slash policy — so “done” is measurable.
  • Where redirects currently live: edge rules, bulk lists, origin config, CMS plugins. You will be editing targets in a moment.

How to verify

Count hops from every entry variant in one loop:

for u in http://example.com https://example.com http://www.example.com https://www.example.com; do
  printf '%-30s ' "$u"
  curl -sIL -o /dev/null -w '%{num_redirects} hops -> %{url_effective} (%{response_code})\n' "$u/"
done

Anything above 1 (and any final code other than 200) goes on the fix list. Print a full chain to see each intermediate URL and who issued it:

curl -sIL 'http://example.com/pricing?utm_source=ad' | grep -iE 'HTTP/|location|server|cf-ray|cf-cache-status|x-redirect-by'

Attribution reads: server: cloudflare with a cf-ray and no cf-cache-status is an edge-generated hop (Always Use HTTPS or a rule); cf-cache-status: DYNAMIC or HIT on a redirect means the origin issued it (or the edge cached the origin’s answer); x-redirect-by: WordPress names the CMS. Watch the location values to confirm the query string survives every hop. For a single hop in isolation:

curl -sI 'https://example.com/old-campaign' | grep -iE 'HTTP/|location|server|cf-ray'

And when you need to know what the origin does without the edge in front (-k for an Origin CA certificate):

curl -skI --resolve www.example.com:443:203.0.113.10 https://www.example.com/pricing | grep -iE 'HTTP/|location'

The fix

  1. Collapse scheme and host into one landing. Point the host-canonicalization Redirect Rule at the absolute final form — https://www.example.com plus the path — so the worst entry (http:// on the wrong host) costs two hops and everything else costs one or zero. Rule mechanics live in the Rules documentation.
  2. Fold the slash hop into the redirect targets. If the site’s final form has a trailing slash, every rule and list entry should target the slashed form directly, so normalization never needs its own hop.
  3. Re-point legacy redirects at final URLs. The chain-builder nobody notices: a bulk entry from 2019 targets /old-blog/post, which now 301s to /articles/post/. Update list targets whenever canonicalization changes — a redirect should always land on a 200.
  4. Preserve the query string at every hop. Check the preserve toggle on rules and confirm with the campaign-parameter curl above; silently dropped utm parameters are how attribution dies.
  5. Re-run the loop and set the acceptance bar. Every tracked entry at 0 or 1 hops, final status 200. Keep the loop output in the ticket as the before-and-after.

When this fix is wrong

  • Flows that redirect by design — login round trips, OAuth, short-link services — are not chains to collapse; audit them for correctness, not hop count.
  • Deliberate temporary redirects (A/B tests, maintenance windows) should stay 302/307 and out of the canonical chain math.
  • The chain lives outside your control — a partner’s tracking domain adding hops before traffic reaches you. Measure from your first owned URL.

Common mistakes

  • Auditing in a browser. Cached 301s and HSTS make the chain look shorter or longer than it is; curl is the instrument.
  • Testing only the homepage. Chains concentrate on legacy deep links and campaign URLs, exactly where nobody looks.
  • Counting hops but ignoring the final status. A one-hop redirect into a 404 passes the hop test and still loses the visitor.
  • Fixing the rule but not the bulk-list targets, so old entries keep landing on intermediate URLs and the chain regrows.
  • Treating one clean run as permanent. Every new rule, plugin, or migration can add a hop; the audit is a regression test, not a one-off.

Prevention

Keep the audit loop in the repo as a script, run it after every rules or DNS change, and extend the URL list whenever a campaign or migration creates new entry points. For recurring use across many sites, the same method is packaged in our redirect tracer, and the CMS-side hunt is covered in finding and fixing redirect chains.

If redirects keep fighting each other across Cloudflare, the origin, and the CMS, Stack Harbor untangles that chain as part of Managed Cloud Ops — book an infrastructure review.