Curl Follow Redirect



This curl recipe shows you how to make curl always follow 301, 302, 303, or any other 3XX redirect. By default, curl doesn't follow redirects. To make it follow all redirects, use the -L command line option.

FollowFollowFile

Follow Any Redirect

  • The URL redirect checker follows the path of the URL. It will show you the full redirection path of URLs, shortened links, or tiny URLs. Also referred to as a url checker, redirect checker, link tracker, url tracker, redirect tracer, link follower, 301 redirect checker, redirect tracker, URL tester, and so on.
  • If you need to follow redirects within your php code using Curl and the openbasedir is set you came into some trouble. If you disable this directive all your directories with a 777 permission are not safe (if one or more website on the same server has some security issues).
  • CURLOPTMAXREDIRS can be used to limit the number of redirects libcurl will follow. Libcurl limits what protocols it automatically follows to. The accepted protocols are set with CURLOPTREDIRPROTOCOLS. By default libcurl will allow HTTP, HTTPS, FTP and FTPS on redirect (7.65.2).
Curl Follow Redirect

This recipe uses the -L argument that forces curl to follow all possible redirects. In this recipe, curl is requesting http://catonmat.net but as this website has moved to https, it sends a 301 redirect response to https://catonmat.net. Curl sees it, follows it, and fetches the https version of the website.

CURLOPTFOLLOWLOCATION(3) curleasysetopt options CURLOPTFOLLOWLOCATION(3) NAME CURLOPTFOLLOWLOCATION - follow HTTP 3xx redirects SYNOPSIS #include curl/curl.h CURLcode curleasysetopt(CURL.handle, CURLOPTFOLLOWLOCATION, long enable); DESCRIPTION A long parameter set to 1 tells the library to follow any Location: header that the server.

Created by Browserling

These curl recipes were written down by me and my team at Browserling. We use recipes like this every day to get things done and improve our product. Browserling itself is an online cross-browser testing service powered by alien technology. Check it out!

Curl Follow Redirect Download

Redirect

Secret message: If you love my curl recipe, then I love you, too! Use coupon code CURLLING to get a discount at my company.