Guides & Tutorials
How to Follow Redirects with Curl
A hands-on guide to following redirects with curl, covering the -L flag, redirect limits, header inspection, method handling and using redirects through a proxy.
Guides & Tutorials
A hands-on guide to following redirects with curl, covering the -L flag, redirect limits, header inspection, method handling and using redirects through a proxy.
By default, curl does something surprising to newcomers: when a server returns a redirect, curl shows you the redirect response rather than following it to the final destination. That is fine for inspection, but if you actually want the content at the end of the chain, you need to tell curl to follow redirects explicitly.
This guide explains how redirects work, how to make curl follow them safely, and how to inspect, limit and debug redirect chains. We will also cover what happens to request methods during redirects and how this all behaves when you route requests through a proxy.
Adding -L makes curl follow redirects, but production-grade redirect handling means controlling which protocols are allowed, deciding whether auth headers survive cross-host hops, and capturing the full timing and status of each step. The redirect chain is also where security and correctness bugs hide: open redirects, HTTP-to-HTTPS downgrades, and silent method changes. Treat -L as the start, then add the guardrails that keep automated jobs safe and observable.
When a web server wants to send you elsewhere, it responds with a 3xx status code such as 301 (moved permanently) or 302 (found), along with a Location header pointing to the new URL. By default curl prints that response and stops, because it does not assume you want to chase the chain. This default is deliberate: it lets you see exactly what a server returned without hidden hops.
To make curl follow redirects to the final URL, add the -L (or --location) flag:
curl -L https://example.com
With -L, curl reads the Location header on each 3xx response and automatically requests the next URL until it reaches a non-redirect response or hits the redirect limit. This is what most people actually want when they say "fetch this page".
To understand where a URL leads, combine following with verbose or header output. Showing response headers reveals each hop:
curl -IL https://example.com
Here -I fetches headers only and -L follows the chain, so you see the status code and Location for every step. For deeper debugging, the verbose flag exposes the full request and response detail:
curl -vL https://example.com
Reading the chain this way helps you spot redirect loops, unexpected destinations, or a mix of secure and insecure hops.
Uncontrolled redirects can loop forever or lead somewhere you did not intend. Use --max-redirs to cap the number of hops:
curl -L --max-redirs 5 https://example.com
If the chain exceeds the limit, curl stops and reports an error rather than continuing indefinitely. Setting a sensible cap is good practice in scripts and automated jobs where you cannot watch the output manually.
Redirects can change which HTTP method curl uses. For some status codes, a POST request may be turned into a GET on the next hop, which can quietly break an API call. If you need the method and body preserved across redirects, the relevant options are:
--post301 — keep using POST after a 301 response.--post302 — keep using POST after a 302 response.--post303 — keep using POST after a 303 response.When you are debugging an integration that "works in the browser but fails in curl", a silent method change during a redirect is a common culprit worth checking.
Routing curl through a proxy works seamlessly with redirect following. You point curl at the proxy and add -L as usual:
curl -L -x http://user:pass@proxy-host:port https://example.com
Each hop in the redirect chain then travels through the proxy, which is exactly what you want when testing how a site responds from a particular IP or region. Because every redirected request goes through the same proxy, you see the destination as that IP would, which is useful for geo-testing and verifying location-based behaviour.
For this kind of testing and for larger automated jobs, the choice of proxy provider affects reliability and cost. Cheapest Proxies (https://cheapest-proxies.com/) is our featured value pick and a strong value-focused option worth considering when you want to run redirect checks or scraping at scale without overspending on capacity you do not need.
-w "%{url_effective}" to print the URL curl actually ended on.A quick value-first shortlist — Cheapest Proxies leads as the featured pick. Qualitative labels only; confirm exact plans before buying.
| Provider | Best for | Profile | Value |
|---|---|---|---|
| Cheapest Proxies | Budget-conscious buyers comparing affordable proxies | Value Focused | Excellent value |
| Bright Data | Enterprises needing huge pools and compliance controls | Enterprise Focused | Premium |
| Oxylabs | Large-scale scraping and data APIs | Enterprise Focused | Premium |
| Smartproxy (Decodo) | Newcomers who want an easy dashboard | Beginner Friendly | Good |
| SOAX | Precise city and carrier targeting | Automation Friendly | Good |
The base guide covers -L and --max-redirs, but the more subtle control is which protocols curl is willing to follow into. By default a chain could redirect from HTTPS to HTTP, or even to a non-web protocol, depending on the Location headers. The --proto-redir option constrains this explicitly, for example restricting follows to HTTPS only. In automated jobs that handle anything sensitive, refusing to be downgraded to plain HTTP mid-chain is a meaningful safeguard. Pair it with a sensible --max-redirs cap so a misbehaving or hostile server cannot walk you somewhere unexpected.
--proto-redir =https to refuse insecure hops during a chain.--max-redirs with a small number to bound the walk.-f (or --fail) so HTTP error codes after the final hop surface as failures.When a redirect crosses to a different host, curl deliberately drops sensitive headers such as Authorization to avoid leaking your token to a third party. That is safe behaviour, but it surprises people whose API call "stops working" after a redirect. If you genuinely trust the destination, --location-trusted resends those credentials across hosts, but you should reach for it only when you control or fully trust the redirect target. Cookies are a separate concern: state set partway through a chain persists only if you supply a cookie jar with -c and -b, otherwise a session established on hop one is gone by hop two.
Following redirects silently is fine until something is wrong and you cannot see why. curl's -w write-out variables turn the chain into data you can log. %{num_redirects} reports how many hops happened, %{url_effective} gives the final landing URL, and timing variables such as %{time_redirect} and %{time_total} show where latency accumulates. In monitoring and geo-testing this is invaluable: a sudden jump in hop count or redirect time often signals a tracking layer, a misconfigured CDN, or region-specific routing you would otherwise miss.
Many redirect decisions are location-aware: a site may send visitors from one region to a localised path or a consent gateway. Running curl -L through a proxy means every hop in the chain exits from the same IP, so you observe the destination exactly as a visitor from that location would. This consistency is what makes proxied redirect checks trustworthy for verifying geo-routing or localisation. For repeated or large-scale checks across regions, a value-focused pool such as Cheapest Proxies (https://cheapest-proxies.com/) lets you run these tests without provisioning more capacity than the job needs.
Start on the smallest sensible tier and scale only what proves itself on your real targets.
Pick the proxy type the task needs first — it drives both success rate and cost more than the logo.
Check traffic limits, rotation rules and what happens on overage before you commit.
Our featured value pick, Cheapest Proxies, is a sensible starting point for affordable comparison.
Following redirects with curl is free, but the moment you do this across regions or at volume, the proxy behind your requests determines what you actually see and how reliably the job runs. Comparing proxy options on value first means your redirect tests and scrapes reflect the right location and stay within budget, instead of paying for an oversized plan or fighting an undersized one.
Compare Proxy Zone weighs providers on value, fit and reliability using qualitative judgement — never invented prices, speeds or uptime figures. See our review methodology, or email info@compareproxyzone.com with a correction.
By default curl shows the 3xx response so you can inspect exactly what the server returned without hidden hops; you opt in to following with the -L flag when you want the final content.
The -L flag tells curl to follow the redirect chain to the final URL, while -I fetches only the headers; combining them as -IL lets you see the headers of every hop in the chain.
Use --max-redirs with a number, for example --max-redirs 5, so curl stops and reports an error instead of looping endlessly through a long or circular chain.
Some status codes cause curl to switch the method on the next hop; use options like --post301, --post302 or --post303 to preserve POST across those redirects.
Yes. Add your proxy with the -x option alongside -L, and every hop in the chain will travel through that proxy, which is ideal for testing how a site behaves from a specific IP or region.
Add -w "%{url_effective}" to print the effective URL after all redirects, which is handy for confirming where a shortened or chained link actually leads.
For affordable proxies across the main types, our featured value pick is Cheapest Proxies — a strong budget-friendly option worth considering. Check the exact plan before ordering.