A redirect chain is a URL that reaches its final destination through two or more redirects instead of one. A redirect loop is a chain that never ends. To fix a chain, find the final URL, then rewrite every rule and link so each old URL points straight to it in a single hop. Google says long chains have a negative effect on crawling [1], and it advises redirecting directly to the final destination [2].
How chains form
Chains rarely come from one bad rule. They come from several correct rules, each added by a different layer: the CDN, the web server, the application, a CMS plugin. Each layer fixes one thing and passes the request on.
A typical four-layer chain:
| Hop | Request | Response | Added by |
|---|---|---|---|
| 1 | http://example.com/pricing | 301 to https://example.com/pricing | Force-HTTPS rule |
| 2 | https://example.com/pricing | 301 to https://www.example.com/pricing | Canonical-host rule |
| 3 | https://www.example.com/pricing | 301 to https://www.example.com/pricing/ | Trailing-slash rule |
| 4 | https://www.example.com/pricing/ | 200 | n/a |
That is three redirects and four requests for one URL. Other common sources:
- Migrations stacked on migrations.
/oldgoes to/2022/old, which later goes to/new. Nobody went back and updated the first rule. - Internal links to old URLs. Navigation, footers and old posts still point at a URL that redirects, so every crawl and every click pays the extra hop.
- Sitemaps listing redirected URLs. The sitemap sends crawlers into a chain on purpose.
- Language or device redirects layered on top of host and scheme rules.
How long a chain can be before it matters
Google's site-move documentation says Googlebot can follow up to 10 hops in a redirect chain, but that you should redirect directly to the final destination [2]. Treat 10 as a ceiling, not a target. Other clients may have different limits, and every hop adds a round trip for users too.
Google also says there are no fixed crawl frequencies, and that crawl speed depends on site size and how fast crawling is possible [2]. On a small site, a few chains will not exhaust anything. The cost is mostly latency and signals pointing at the wrong URLs. The crawl budget guide covers when the crawl cost is worth worrying about.
Find chains and loops
Test single URLs with curl
curl -I sends a HEAD request and prints only the headers. Add -L to follow redirects, and filter for the lines you care about:
curl -sIL http://example.com/pricing | grep -iE '^(HTTP|location)'
Output for the chain above:
HTTP/1.1 301 Moved Permanently
Location: https://example.com/pricing
HTTP/2 301
location: https://www.example.com/pricing
HTTP/2 301
location: https://www.example.com/pricing/
HTTP/2 200
Count the 301 lines. More than one means a chain.
To check a list of URLs, print the hop count and final URL for each:
while read -r url; do
curl -sIL -o /dev/null --max-redirs 10 \
-w '%{num_redirects} %{http_code} %{url_effective} <- '"$url"'\n' "$url"
done < urls.txt | sort -rn
Anything with a count above 1 is a chain. Put the four variants of your home page and your top 20 URLs in urls.txt first. Some servers answer HEAD differently from GET. If a result looks wrong, repeat it with curl -sL -o /dev/null -D - URL.
Spot loops
A loop makes curl stop at its redirect limit. With --max-redirs 10, curl errors out after 10 redirects ("Maximum (10) redirects followed"). Browsers show their own "too many redirects" error. Ahrefs' help center defines a redirect loop as a chain that gets stuck redirecting to one of its own elements, so the final URL never resolves [5]. Its Site Audit reports this as an issue [5].
Crawl the whole site
curl covers samples. To find every chain, crawl the site with a crawler you already use and export the URLs that return 3xx. Then run those through the curl loop above. A crawl catches links to redirected URLs. Server logs show which redirects crawlers actually hit.
Fix: consolidate into one hop
The method is the same for every stack.
- Pick the one final form of every URL: scheme, host, trailing slash or not, lowercase or not.
- Write one rule that sends every non-canonical variant straight to that form. Do not let a rule send traffic to a URL that another rule will redirect again.
- Flatten old redirect maps. Replace
A→BandB→CwithA→CandB→C. - Update internal links, canonicals and sitemap entries to the final URL. See the canonical tags guide and the XML sitemap guide.
- Use permanent redirects for permanent moves. Google recommends server-side permanent redirects such as 301 and 308 where possible [2].
NGINX: one hop for scheme and host
Give each non-canonical entry point its own server block that returns the final URL:
# http, both hosts -> final
server {
listen 80;
server_name example.com www.example.com;
return 301 https://www.example.com$request_uri;
}
# https, bare host -> final
server {
listen 443 ssl;
server_name example.com;
# ssl_certificate lines here
return 301 https://www.example.com$request_uri;
}
# https, www: the real site
server {
listen 443 ssl;
server_name www.example.com;
# ...
}
return is a direct response and does not re-enter the rewrite phase. NGINX's rewrite directives are different: the documentation says the rewrite cycle repeats no more than 10 times, and a misconfigured set of rules can end in a 500 error [3].
Apache: one rule, and stop processing
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^/?(.*)$ https://www.example.com/$1 [R=301,END]
The flag matters. Apache documents that [L] can still lead to re-processing of rewritten requests in per-directory context, which can cause loops [4]. [END] stops all further rewrite processing, including later passes, and is the cleanest way to prevent loops [8]. On .htaccess files, prefer [END] over [L].
The trailing-slash rule
The slash rule is the usual reason a chain survives a host/scheme cleanup. It often lives in the CMS or framework, outside your server config. There are two ways out:
- Make the app's slash redirect the only place that rule exists. Then a request on the canonical host costs at most one hop.
- Better, compute the final path in the same rule that fixes scheme and host, so
http://example.com/pricinggoes straight tohttps://www.example.com/pricing/. This takes care with query strings and file extensions, so test it against real URLs.
Either way, link internally to the slash-final form so normal navigation never triggers the rule.
Common causes of loops
- Two layers disagree. The CDN sends www to bare host, the origin sends bare host to www.
- Slash add and slash remove. A server rule adds the slash and the app strips it.
- HTTPS behind a proxy. The origin sees plain HTTP from the CDN and redirects to HTTPS forever. Fix the forwarded-protocol handling or the CDN's origin setting, not the redirect.
- A redirect to itself. A pattern like
/blog/(.*)redirecting to/blog/$1. - Rewrite rules that re-match their own output, which is why the
[END]andreturnadvice above matters.
To debug a loop, run curl -sIL --max-redirs 5 URL | grep -iE '^(HTTP|location)' and read the Location values. The pair that alternates tells you which two rules collide.
Method changes on non-GET requests
If forms or API endpoints are being redirected, the status code matters. curl's man page says that for 307 and 308 the request method is preserved, while for 301, 302 and 303 curl may switch the method to GET [6]. For a permanent move of an endpoint that receives POST, 308 is the safer choice. Check how your own clients behave.
Verify after the change
- Re-run the curl loop on your URL list. Every line should show 0 or 1 redirects.
- Test the four variants of the home page (http/https, with and without www) plus one deep URL with and without the trailing slash.
- Confirm the final URL returns 200 and its canonical tag points at itself. The HTTP status codes guide covers what each code signals.
- Re-crawl and confirm no internal link points at a redirecting URL.
What to do next
- Run the curl loop on your home page variants and top URLs today.
- List every layer that can redirect: CDN, server, app, plugins. Then delete overlapping rules.
- Fix internal links, canonicals and sitemap entries to the final URL.
- Add a redirect check to your recurring technical SEO checklist and to your pre-launch checks for any migration.