Skip to content
MtrXTools

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

  1. Run curl -sIL --max-redirs 10 URL to print each hop and find where it loops.
  2. Make the origin trust X-Forwarded-Proto, or forward HTTPS to the origin, so it stops redirecting.
  3. Pick one canonical host (www or apex) and redirect only in one place.
  4. For pages that need a session, use -c and -b with a cookie jar.
Trace the redirect chain

Got a different message? Paste it into the error explainer.

Related errors

All 34 Command line & code errors