1CURLOPT_FOLLOWLOCATION(3) curl_easy_setopt options CURLOPT_FOLLOWLOCATION(3)
2
3
4
6 CURLOPT_FOLLOWLOCATION - follow HTTP 3xx redirects
7
9 #include <curl/curl.h>
10
11 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FOLLOWLOCATION, long
12 enable);
13
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
17 response. The Location: header can specify a relative or an absolute
18 URL 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
34 request: For 301, 302 and 303 responses libcurl will switch method to
35 GET unless CURLOPT_POSTREDIR(3) instructs libcurl otherwise. All other
36 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
45 0, disabled
46
48 HTTP(S)
49
51 CURL *curl = curl_easy_init();
52 if(curl) {
53 curl_easy_setopt(curl, CURLOPT_URL, "http://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
62 Along with HTTP
63
65 Returns CURLE_OK if HTTP is supported, and CURLE_UNKNOWN_OPTION if not.
66
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.66.0 July 16, 2019 CURLOPT_FOLLOWLOCATION(3)