1--- 2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3SPDX-License-Identifier: curl 4Title: CURLOPT_MAXREDIRS 5Section: 3 6Source: libcurl 7See-also: 8 - CURLINFO_REDIRECT_COUNT (3) 9 - CURLINFO_REDIRECT_URL (3) 10 - CURLOPT_FOLLOWLOCATION (3) 11Protocol: 12 - HTTP 13--- 14 15# NAME 16 17CURLOPT_MAXREDIRS - maximum number of redirects allowed 18 19# SYNOPSIS 20 21~~~c 22#include <curl/curl.h> 23 24CURLcode curl_easy_setopt(CURL *handle, CURLOPT_MAXREDIRS, long amount); 25~~~ 26 27# DESCRIPTION 28 29Pass a long. The set number is the redirection limit *amount*. If that 30many redirections have been followed, the next redirect triggers the error 31(*CURLE_TOO_MANY_REDIRECTS*). This option only makes sense if the 32CURLOPT_FOLLOWLOCATION(3) is used at the same time. 33 34Setting the limit to 0 makes libcurl refuse any redirect. 35 36Set it to -1 for an infinite number of redirects. This allows your application 37to get stuck in never-ending redirect loops. 38 39# DEFAULT 40 4130 (since 8.3.0), it was previously unlimited. 42 43# EXAMPLE 44 45~~~c 46int main(void) 47{ 48 CURL *curl = curl_easy_init(); 49 if(curl) { 50 curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/"); 51 52 /* enable redirect following */ 53 curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); 54 55 /* allow three redirects */ 56 curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3L); 57 58 /* Perform the request */ 59 curl_easy_perform(curl); 60 } 61} 62~~~ 63 64# AVAILABILITY 65 66Along with HTTP 67 68# RETURN VALUE 69 70Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not. 71