×


Solution to curl maximum redirects followed

Are you facing curl maximum redirects followed? We have a fix for it.  Read on....




We have previously helped numerous customers fix curl command related issues as part of our Server Support Services.

Now let us see why this error occur and how to fix it.


More about curl redirect

Curl is a very important command line tool which is responsible for conveying any HTTP request from an external source for a client back to the server.
What this means is that curl command takes care of redirects automatically and helps to get data when it send request via an URL. Below you will see an example of a curl redirect;

#<HTML><HEAD><meta http-equiv=”content-type” content=”text/html;charset=utf-8″>
#<TITLE>curl Redirect</TITLE></HEAD><BODY>
#<H1>Curl redirection example</H1>
#Read on
#<A HREF=”http://www.website.com/”>OK</A>.
#</BODY></HTML>


When called on a command prompt, it takes the following format;

curl -L [url]


What triggers curl maximum redirects followed error

This error curl requests fail after redirecting 50 times when accessing some http source. For example if the request is sent via;

curl ‘website.com’ -L -o ‘output.txt’


An error like this is displayed;

curl: (47) Maximum (50) redirects followed
No data in the output.txt file.


What this signifies is that the way in which maximum number of redirects is processed by curl is unique. 50 times is the default. Additionally, in curl, cookies is enabled by default.

How to solve curl maximum redirects followed error

To solve this error, you can apply the following tips;

i. Using other HTTP capable commands such as wget to test the source URL is a good way to troubleshoot the problem to see if the same error will occur. If it doesn't throw any error, that means the cookies may be responsible. In this case, enabling cookies will fix it by using the following command;

curl -v –cookie “USER_TOKEN=Yes” http://website.com/
curl -v –cookie-jar cookie_file http://website.com/


ii. Removing the redirect limits can also fix this issue. You can set the option "–max-redirs" to -1.

Need support in solving curl errors? We are available.


Conclusion

Steps to fix curl maximum redirects followed error.