Webmaster Bench

Tools / Guides / Redirect chains with curl -I: reading them, and 301 vs 302

Redirect chains with curl -I: reading them, and 301 vs 302

One command shows every redirect between a link and the page it ends on. Here is how to read the output, what Google does with each status code, and the server defaults that produce 302s nobody meant.

Published 2026-11-20. Last updated 2026-11-20. Written by Webmaster Bench; see About for how the guides are made and checked.

Try it: HTTP Header & Redirect Checker: Paste curl output to explain a redirect chain, status codes, caching and security headers.

The command

curl -sIL http://example.com/Blog

What each flag does, from the curl manual:

  • -I (--head) fetches the headers only, using an HTTP HEAD request.
  • -L (--location) follows a Location: header on a 3xx response and, used with -I, prints the headers of every page it requests. Without -L you see only the first hop. curl follows up to 50 redirects by default.
  • -s hides the progress meter.

One caveat. Some servers answer HEAD differently from GET, for example with a 405 or 404, or with different headers. If the result looks wrong, repeat with a real GET that prints only the headers: curl -sL -D - -o /dev/null URL.

Worked example: four responses for one link

An old link points to http://example.com/Blog. curl prints this (other headers removed for space):

HTTP/1.1 301 Moved Permanently
Location: https://example.com/Blog

HTTP/2 301
location: https://www.example.com/Blog

HTTP/2 302
location: /blog/

HTTP/2 200
content-type: text/html; charset=utf-8

Each block that starts with HTTP/ is one response. Pasted into the HTTP header checker with the start URL, it becomes this chain:

#URL requestedStatusGoes to
1http://example.com/Blog301 Moved Permanentlyhttps://example.com/Blog
2https://example.com/Blog301 Moved Permanentlyhttps://www.example.com/Blog
3https://www.example.com/Blog302 Foundhttps://www.example.com/blog/
4https://www.example.com/blog/200 OK

and these findings:

  • Warning: 3 redirects before the final response. Point the first URL straight at the final one; Googlebot follows at most 10 hops and each hop costs time.
  • Warning: The chain contains a temporary redirect (302 or 307). If the move is permanent, use 301 or 308.
  • OK: Final response is 200 OK.

Three hops come from three separate rules, each written on its own: one sends HTTP to HTTPS, one adds www, and one fixes the path. Each is correct alone; together they make a chain. And the last hop is a 302, which tells Google the move is temporary.

301 vs 302, 307 and 308: what Google does

StatusMeaningGoogle
301 Moved PermanentlyPermanentUses the redirect as a strong signal that the target should be canonical; shows the new URL in results.
308 Permanent RedirectPermanent, keeps the request methodTreated the same as 301.
302 FoundTemporaryA weak signal. Shows the source URL in results; the target may still be indexed if other signals point to it.
307 Temporary RedirectTemporary, keeps the request methodTreated the same as 302.
303 See Other"Go and GET this other URL"Listed by Google with the temporary redirects.

So the choice is about which URL you want in search results: a permanent redirect for the new one, a temporary redirect to keep the old one. Use a temporary redirect only when the old URL really will come back, for example while a page is briefly replaced by a notice. Google also says that, although it treats 301 and 308 alike (and 302 and 307 alike), you should use the code that fits, because other clients may handle them differently.

Google's crawlers follow up to 10 redirect hops by default. Long chains are rare in practice; the reason to shorten them is speed and clarity, since every hop is another round trip for every visitor.

Advertisement

Where unintended 302s come from

Most temporary redirects on a site were never chosen. They are the default of the tool that made them:

Written asStatus sentPermanent version
PHP: header("Location: https://...");302, unless a 201 or 3xx status was already setheader("Location: https://...", true, 301);
Apache: Redirect "/old" "https://..."302 when no status is givenRedirect permanent "/old" "https://..." (or 301)
nginx: return https://...;302 when only a URL is givenreturn 301 https://...;
nginx: rewrite ... redirect;302rewrite ... permanent;

If curl shows a 302 you did not mean, look for a line like these in the configuration or code that serves that URL.

The fix

Send every old variant straight to the final URL in one permanent redirect. For the example, the redirect for http://example.com/Blog should go directly to https://www.example.com/blog/:

HTTP/1.1 301 Moved Permanently
Location: https://www.example.com/blog/

HTTP/2 200
content-type: text/html; charset=utf-8

The header checker's findings for this version:

  • OK: One permanent redirect: the clean way to move a URL.
  • OK: Final response is 200 OK.

In practice that means one rule that builds the final URL (scheme, host and path together) instead of several rules that each fix one part, or at least ordering the rules so the path fix happens in the same response as the scheme and host fix. Then:

  1. Update internal links, canonical tags and sitemaps to the final URL, so that your own pages do not go through the redirect at all. Google's sitemap help asks you to replace redirecting URLs in sitemaps with the URLs that should be crawled.
  2. Run curl -sIL again on each old variant: http:// and https://, with and without www, with and without the trailing slash.
  3. Keep the redirects in place. Google's site-move guidance says to keep them for as long as possible, and at least a year.

Two things curl does not show

  • JavaScript and meta refresh redirects. curl does not run JavaScript or read HTML, so a page that redirects that way shows as a 200. Google can follow both, but recommends server-side redirects where possible.
  • Upgrades the browser does by itself. Once a browser has received a Strict-Transport-Security header from a site, later http:// loads of that site "use HTTPS immediately, without requiring a redirect" (MDN). Testing an http:// URL in that browser therefore tells you nothing about the server's own redirect. curl keeps no such memory unless you give it a cache file with --hsts, so it shows what the server sends.

Sources

Advertisement