1CURLOPT_FOLLOWLOCATION(3)  curl_easy_setopt options  CURLOPT_FOLLOWLOCATION(3)
2
3
4

NAME

6       CURLOPT_FOLLOWLOCATION - follow HTTP 3xx redirects
7

SYNOPSIS

9       #include <curl/curl.h>
10
11       CURLcode  curl_easy_setopt(CURL  *handle,  CURLOPT_FOLLOWLOCATION, long
12       enable);
13

DESCRIPTION

15       A long parameter set to 1 tells the library  to  follow  any  Location:
16       header  that  the  server  sends as part of an HTTP header in a 3xx re‐
17       sponse. The Location: header can specify a relative or an absolute  URL
18       to follow.
19
20       libcurl will issue another request for the new URL and follow new Loca‐
21       tion: headers all the way until no  more  such  headers  are  returned.
22       CURLOPT_MAXREDIRS(3)  can  be  used  to  limit  the number of redirects
23       libcurl will follow.
24
25       libcurl limits what protocols it automatically follows to. The accepted
26       protocols  are  set with CURLOPT_REDIR_PROTOCOLS(3). By default libcurl
27       will allow HTTP, HTTPS, FTP and FTPS on redirect (7.65.2).  Older  ver‐
28       sions  of  libcurl  allowed all protocols on redirect except those dis‐
29       abled for security reasons: Since 7.19.4 FILE and SCP are disabled, and
30       since 7.40.0 SMB and SMBS are also disabled.
31
32       When  following  a  Location:, the 3xx response code that redirected it
33       also dictates which request method it will use in  the  subsequent  re‐
34       quest:  For  301, 302 and 303 responses libcurl will switch method from
35       POST to GET unless CURLOPT_POSTREDIR(3)  instructs  libcurl  otherwise.
36       All other 3xx codes will make libcurl send the same method again.
37
38       For  users  who think the existing location following is too naive, too
39       simple or just lacks features, it is very  easy  to  instead  implement
40       your  own  redirect follow logic with the use of curl_easy_getinfo(3)'s
41       CURLINFO_REDIRECT_URL(3) option instead  of  using  CURLOPT_FOLLOWLOCA‐
42       TION(3).
43

DEFAULT

45       0, disabled
46

PROTOCOLS

48       HTTP(S)
49

EXAMPLE

51       CURL *curl = curl_easy_init();
52       if(curl) {
53         curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
54
55         /* example.com is redirected, so we tell libcurl to follow redirection */
56         curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
57
58         curl_easy_perform(curl);
59       }
60

AVAILABILITY

62       Along with HTTP
63

RETURN VALUE

65       Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
66

SEE ALSO

68       CURLOPT_REDIR_PROTOCOLS(3), CURLOPT_PROTOCOLS(3), CURLOPT_POSTREDIR(3),
69       CURLINFO_REDIRECT_URL(3), CURLINFO_REDIRECT_COUNT(3),
70
71
72
73libcurl 7.79.1                 November 04, 2020     CURLOPT_FOLLOWLOCATION(3)
Impressum