curl: (47) Maximum (50) redirects followed
curl stopped in a redirect loop
Seen in curl -L, libcurl (CURLE_TOO_MANY_REDIRECTS), PHP
curl followed redirects until it hit its limit, which almost always means the server is redirecting in a loop.
Common causes
- An HTTP to HTTPS redirect behind a load balancer or CDN that talks plain HTTP to the origin, so the origin keeps redirecting.
- Conflicting www and apex redirects between the CDN and the application.
- A login or cookie check that redirects again because curl is not sending the expected cookie.
How to fix it
- Run curl -sIL --max-redirs 10 URL to print each hop and find where it loops.
- Make the origin trust X-Forwarded-Proto, or forward HTTPS to the origin, so it stops redirecting.
- Pick one canonical host (www or apex) and redirect only in one place.
- For pages that need a session, use -c and -b with a cookie jar.
Got a different message? Paste it into the error explainer.
Related errors
- curl: (18) transfer closed with outstanding read data remaining · The connection closed before the body finished
- curl: (22) The requested URL returned error · The server answered with an HTTP error status
- curl: (92) HTTP/2 stream 0 was not closed cleanly: PROTOCOL_ERROR (err 1) · The server reset an HTTP/2 stream
- unable to get local issuer certificate · The client can't find the certificate's issuer
- unable to verify the first certificate · The intermediate certificate is missing
- certificate has expired · The server certificate has expired
- self signed certificate in certificate chain · The chain ends in an untrusted root
- wrong version number · TLS spoken to something that isn't TLS
- curl: (6) Could not resolve host · The hostname doesn't resolve
- curl: (7) Failed to connect · The connection was refused or unreachable
- curl: (28) Operation timed out · The request timed out
- curl: (51) SSL: no alternative certificate subject name matches target host name · The certificate doesn't match the hostname