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