Follow Redirects with Curl

Follow Redirects with Curl

When working with Curl, you may encounter scenarios where the server responds with a redirection status code (3xx). By default, Curl doesn't automatically follow these redirects. However, you can easily enable this feature to ensure your requests seamlessly navigate through redirections. This tutorial explains how to follow redirects with a Curl.

The simplest way to instruct Curl to follow redirects is by using the -L or --location option. When you append this option to your Curl command, it tells Curl to follow any redirection responses.

curl -L https://httpbin.org/relative-redirect/1
curl --location https://httpbin.org/relative-redirect/1

This command will send a request to the server and automatically follow any redirection responses until it reaches the final destination.

Leave a Comment

Cancel reply

Your email address will not be published.