To follow redirects with cURL, you can use the -L
or --location
flag. This flag tells curl to follow any redirection response from the server.
Here is an example command:
curl -L <URL>
Replace <URL>
with the actual URL you want to access. By default, curl will follow up to 50 redirects, but you can change this limit by using the --max-redirs
option followed by the maximum number of redirects to follow.
curl -L --max-redirs 10 <URL>
This command will follow up to 10 redirects.
By using the -I
or --head
flag, you can retrieve only the headers and check if the server has responded with any redirection information.
curl -I <URL>
Note that when curl follows a redirect, it will not show the content of the redirected page unless the -L
or --location
flag is used.