[b]"How to make curl follow redirect properly? Need help with curl follow redirect behavior."[/b] Alternatively, for

18 Replies, 851 Views

Title: Why isn't curl follow redirect working as expected?

Hey folks,

I'm having trouble with curl follow redirect. I thought `-L` would handle it automatically, but it’s not following the redirects like it should.

Here’s what I’m running:
```bash
curl -L https://example.com/somepage
```
But it just stops at the first response. Am I missing something?

Tried adding `--max-redirs 10` too, no luck.

Any ideas why curl follow redirect isn’t behaving? Or how to debug this properly?

Thanks!

---

*Alternatively, shorter version:*

Title: How to make curl follow redirect properly?

Yo,

`curl -L` should follow redirects, right? But mine’s not. What gives?

Example:
```bash
curl -L http://some.site/old-url
```
Just hangs or stops early.

Is there a trick to make curl follow redirect *every* time? Help a noob out!

Cheers.
Hey! Had the same issue last week. Turns out some sites block curl follow redirect with user-agent checks. Try adding `-A "Mozilla/5.0"` to your command.

Also, `-v` helps debug—shows headers so you can see if the redirect is even being sent.

If that fails, maybe the server’s doing weird stuff. Try `curl -v -L --post301 --post302 http://example.com` to force it.
Yo, curl follow redirect can be finicky with HTTPS if certs are wonky. Add `-k` to ignore SSL errors and see if that helps.

Also, check if the redirect is a meta refresh or JS—curl won’t follow those, only 3xx HTTP codes.

For debugging, `curl -i -L` shows headers + body. Might reveal the issue.
Happened to me too! curl follow redirect sometimes chokes on relative URLs. Try `--location-trusted` or `--resolve` if DNS is weird.

Pro tip: Use `httpbin.org/redirect/3` to test—it’s a controlled redirect chain. If curl works there, it’s the site’s fault.
Weird. curl follow redirect should work with `-L`. Maybe the server’s sending malformed headers?

Try `curl --raw -L` to see the unfiltered response. Also, `strace curl -L` if you’re on Linux—might show syscall fails.

If all else fails, `wget` is more forgiving with redirects.
Hey! curl follow redirect might fail if the redirect URL has spaces or weird chars. Try wrapping the URL in quotes.

Example:
```bash
curl -L "http://example.com/weird path"
```

Also, `--max-redirs 10` should work—unless the site’s redirecting infinitely. Check with `-v`.
Yo, OP here. Tried the `-A "Mozilla"` trick and `-v`—turns out the server was sending a 302 but curl was ignoring it. Weird!

Forced HTTP/1.1 and it worked. Still dunno why `-L` didn’t handle it, but thanks y’all!

Gonna mess with `--location-trusted` next. Cheers!
curl follow redirect can break if the server uses HTTP/2 or weird protocols. Try forcing HTTP/1.1 with `--http1.1`.

Another thing: Some CDNs (like Cloudflare) block curl by default. Change the user-agent or use a proxy.
Had this exact issue! curl follow redirect doesn’t handle cookies by default. If the site needs session cookies, add `-b cookies.txt -c cookies.txt`.

Also, `-D headers.txt` dumps response headers—super useful for debugging.
Check if the redirect is a 307/308—those might need `--post307` or `--post308` to handle POST data correctly.

For testing, `curl -L -v http://httpstat.us/301` is a clean way to see if it’s your curl or the site.



Users browsing this thread: 1 Guest(s)