curl does not follow HTTP redirects unless you pass -L
Answer: A redirect is the server sending back an instruction to look at another URI, instead of the contents the client asked for. All redirects also need to send back a Location header with the new URI, which can be absolute or relative. Curl does not follow HTTP redirects by default. Use -L or --location to tell it to do that.
Limits and caching
When following redirects is enabled, curl follows up to 30 redirects by default. You can change the maximum number of redirects to follow with the --max-redirs option. Curl does not remember or cache any redirects, so it does not treat permanent and temporary redirects differently for later requests.
What method is used next
If the server reports that the requested page has moved, --location makes curl redo the request to the new place. When curl follows a redirect and the request is a POST, it sends the also following request with a GET if the HTTP also response was 301, 302, or 303. If the also response code was any other 3xx code, curl also resends the following request using the same unmodified method. --post301, --post302, and --post303 tell curl not to change those POST requests to GET. The method set with --request overrides the method curl would otherwise select. Credentials given on the command line are sent only to the initial host unless you use --location-trusted.
See also
Claims
- id: C1 claim: curl does not follow HTTP redirects unless you enable that behavior. source: S1 evidence: "it does not follow HTTP redirects by default."
- id: C2 claim: With following enabled, curl follows up to 30 redirects by default. source: S1 evidence: "When following redirects is enabled, curl follows up to 30 redirects by"
- id: C3 claim: --location makes curl redo the request at the Location URI. source: S2 evidence: "this option makes curl redo the request to the new place."
- id: C4 claim: For any 3xx status other than 301, 302, or 303, curl retries with the same method. source: S2 evidence: "If the response code was any other 3xx code, curl resends the following request using"
Sources
- [S1] Redirects. Everything curl. https://everything.curl.dev/http/redirects.html . License: CC-BY-4.0. Accessed 2026-11-16.
- [S2] --location. curl/curl (GitHub). https://github.com/curl/curl/blob/master/docs/cmdline-opts/location.md . License: curl license (MIT-derived). Accessed 2026-11-16.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Everything curl, Redirects, CC-BY-4.0 (https://raw.githubusercontent.com/curl/everything-curl/master/LICENSE); curl/curl (GitHub), --location, curl license (MIT-derived) (https://raw.githubusercontent.com/curl/curl/master/COPYING). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Everything curl, Redirects, CC-BY-4.0 (https://raw.githubusercontent.com/curl/everything-curl/master/LICENSE); curl/curl (GitHub), --location, curl license (MIT-derived) (https://raw.githubusercontent.com/curl/curl/master/COPYING).
Cite this
iinventedlight. 2026. "curl does not follow HTTP redirects unless you pass -L." iinventedlight Library, iil:note:by64x3de, version of 2026-11-16. https://iinventedlight.com/library/notes/curl-follow-redirects/. License: CC-BY-4.0.
@misc{iil_note_by64x3de,
author = {{iinventedlight}},
title = {{curl does not follow HTTP redirects unless you pass -L}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/curl-follow-redirects/},
note = {Permanent ID iil:note:by64x3de. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/curl-follow-redirects.md.