How to set curl command to follow the redirects

By default curl will not follow the redirects if any and it will print the redirection response only.

#curl -I http://www.techies-world.com

HTTP/1.1 301 Moved Permanently
Connection: Keep-Alive  
Content-Type: text/html; charset=UTF-8
X-Redirect-By: WordPress
Location: http://techies-world.com/
Vary: Accept-Encoding
X-LiteSpeed-Cache: hit
Date: Sun, 18 Jul 2021 16:56:59 GMT
Server: LiteSpeed

Here we can see that its not providing the data of final redirected url. We can resolve this problem by adding "-L" option with curl command.

#curl -IL http://www.techies-world.com

HTTP/1.1 301 Moved Permanently
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
X-Redirect-By: WordPress
Location: http://techies-world.com/
Vary: Accept-Encoding
X-LiteSpeed-Cache: hit
Date: Sun, 18 Jul 2021 16:59:02 GMT
Server: LiteSpeed

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
Link: <http://techies-world.com/wp-json/>; rel="https://api.w.org/"
Vary: Accept-Encoding
Etag: "2610-1626617472;;;"
X-LiteSpeed-Cache: hit
Date: Sun, 18 Jul 2021 16:59:02 GMT
Server: LiteSpeed

Here curl following all the redirects and providing the response from final endpoint.

That's all…

Leave a Reply

Your email address will not be published. Required fields are marked *