About This Article
This article was created using an automated generation workflow leveraging generative AI. Based on RFC 9110 and official curl documentation, it organizes how to check redirects such as 301 and 302 by separating them into the initial response, intermediate path, and final URL.Verification Status: 📘 Confirmed via RFC and official curl documentation, execution not verified.
Because browsers automatically follow redirects, it can sometimes be difficult to see whether the initial connection was HTTP, whether it was forwarded to a www version, or how many redirect steps occurred.
With curl, you can separately inspect the pre-transfer Location and the final destination URL.
First, Check the Initial Response
curl -I https://example.com/
When status codes like 301, 302, 307, or 308 are returned, check Location.
HTTP/1.1 301 Moved Permanently Location: https://www.example.com/
At this point, curl will not automatically proceed to the next URL if -I is used alone.
Following Redirects with -L
curl -I -L https://example.com/
Adding -L / --location will follow the Location header. If there are multiple steps, the response headers will be displayed in sequence.
sequenceDiagram participant C as curl participant A as URL A participant B as URL B participant C2 as URL C C->>A: Request A-->>C: 301 Location: B C->>B: Request B-->>C: 302 Location: C C->>C2: Request C2-->>C: 200 OK
Finding Only the Final URL
You can display the final URL by using curl’s write-out feature.
curl -sS -L -o /dev/null -w 'HTTP=%{http_code}\nFINAL=%{url_effective}\n' https://example.com/
The following two points should be checked:
http_code: Status of the final responseurl_effective: Finally reached URL
Use Cases
In practice, this is useful for checking the following:
HTTP to HTTPS forwarding
Enforcing www/non-www consistency
301 redirects from old URLs to new URLs
WordPress canonical URL changes
Reverse proxy configurations
Forwarding behavior after implementing a CDN
Pre-authentication URL to login URL transitions
In SEO and site migrations, not only whether a redirection occurs, but also how many hops are involved is also important. Unnecessary multi-stage redirects can serve as a clue for architectural reviews.
Isolating Infinite Loops
With configuration errors such as A -> B -> A, browsers may simply display an error saying “Too many redirects.”
With curl, you can explicitly specify the maximum number of redirects.
curl -I -L --max-redirs 5 https://example.com/
If it exceeds five attempts, an error occurs, allowing you to suspect a loop or excessive forwarding.
Caution with URLs Containing Credentials
If the redirect destination is a different host, handle credentials and cookies with careful verification.
In particular, --location-trusted may send credentials to a different host, so it is safer not to use it without understanding its implications.
When sharing troubleshooting results, make sure not to paste sensitive items such as cookies, Authorization headers, internal URLs, or session information as-is.
Going Beyond the Difference Between 301 and 302
What is required in the field is not just memorizing status codes, but confirming:
Where the initial response was directed
Where it went next
Where the final URL is
What the final status code is
Whether the intended path was followed
Summary
-I: You can check the initial Location-L: You can track redirects%{url_effective}: You can check the final URL--max-redirs: Can be used for investigating redirect loopsHandle redirects involving credentials with caution
Official Documentation and Primary Sources
この記事の更新履歴
この記事は、生成AIを活用した自動レビュー・更新フローにより内容を見直し、必要な修正を反映しています。
2026年9月23日
- 変更curlコマンドのオプション解説部分における文章の途切れや不自然な改行を修正しました。

