Commandcurl

Follow redirects and show headers

Shows every response's headers across a full redirect chain, from the first request down to the final destination, without any body.

Last updated

Commandcurl
curl -IL https://example.com

How it works

-I sends a HEAD request and prints only the response headers, never the body — the fast way to inspect status codes, content type and redirect targets without downloading anything. -L makes curl follow every redirect in the chain instead of stopping at the first response, so combined you see the full sequence of header blocks from the very first hop down to wherever it finally lands.

This combination is the quick diagnostic for "where does this URL actually go, and what does each hop say" — useful for checking that a shortlink, canonical redirect, or CDN rule resolves the way you expect before wiring real traffic through it.

Watch out for

  • →Some servers respond differently to HEAD than to GET (an endpoint might 404 or 405 on HEAD while a real GET works fine) — if the headers look wrong or missing, retest with a real GET that still discards the body: curl -L -D - -o /dev/null https://example.com.
  • →-I alone, without -L, only shows the FIRST response in the chain — you need both flags together, as shown, to see headers for every redirect hop rather than just the first one.
  • →On Windows there's no /dev/null for the GET-with-headers alternative above — use -o NUL instead; the -IL command itself needs no such target since it never downloads a body.

Part by part

-IL
Two flags bundled into one argument, which is why this reads as a single token rather than as -I -L.
-I
Fetch headers only, using a HEAD request. No body is transferred, so this stays fast even against a large file.
L
The second half of the bundle: follow redirects. Together with -I it prints the headers of every hop, which is what makes the whole chain visible.

Common mistakes

  • curl -I https://example.com

    Without -L you see only the first response, so a 301 tells you a redirect exists but not where it ultimately lands. The chain is usually the thing you are trying to inspect.

    curl -IL https://example.com
  • curl -IL https://example.com/api/items

    Some servers handle HEAD differently from GET, or reject it outright, so the headers you see may not be the headers a real request gets. Use -sIL with -X GET when the difference matters.

  • curl -L https://example.com | head

    This downloads the body and shows the start of it, which answers a different question and can pull a large file for nothing. -I is the flag for header inspection.

Questions

How do I see just the final URL?

curl -sIL -o /dev/null -w "%{url_effective}" prints the destination and nothing else. It is the quickest way to expand a shortened link before deciding whether to open it.

Why does the redirect count matter?

Each hop is a full round trip, so a chain of four costs real latency on every request. Search engines also treat long chains poorly, which makes this a useful check after changing a URL structure.

What is the difference between 301 and 302?

301 is permanent and tells clients and search engines to update their reference; 302 is temporary and asks them to keep using the original. Choosing the wrong one either strands the old URL or fails to move the new one.

Can I limit how many redirects it follows?

Yes, --max-redirs takes a number and curl stops there. Useful for detecting a loop, which otherwise runs to curl's default limit before reporting an error.

Related in Commands