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