1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLINFO_REDIRECT_URL
5Section: 3
6Source: libcurl
7See-also:
8  - CURLINFO_REDIRECT_COUNT (3)
9  - CURLINFO_REDIRECT_TIME_T (3)
10  - CURLOPT_FOLLOWLOCATION (3)
11  - curl_easy_getinfo (3)
12  - curl_easy_setopt (3)
13Protocol:
14  - HTTP
15Added-in: 7.18.2
16---
17
18# NAME
19
20CURLINFO_REDIRECT_URL - get the URL a redirect would go to
21
22# SYNOPSIS
23
24~~~c
25#include <curl/curl.h>
26
27CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_REDIRECT_URL, char **urlp);
28~~~
29
30# DESCRIPTION
31
32Pass a pointer to a char pointer to receive the URL a redirect *would* take
33you to if you would enable CURLOPT_FOLLOWLOCATION(3). This can come handy if
34you think using the built-in libcurl redirect logic is not good enough for you
35but you would still prefer to avoid implementing all the magic of figuring out
36the new URL.
37
38This URL is also set if the CURLOPT_MAXREDIRS(3) limit prevented a redirect to
39happen (since 7.54.1).
40
41# %PROTOCOLS%
42
43# EXAMPLE
44
45~~~c
46int main(void)
47{
48  CURL *curl = curl_easy_init();
49  if(curl) {
50    CURLcode res;
51    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
52    res = curl_easy_perform(curl);
53    if(res == CURLE_OK) {
54      char *url = NULL;
55      curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &url);
56      if(url)
57        printf("Redirect to: %s\n", url);
58    }
59    curl_easy_cleanup(curl);
60  }
61}
62~~~
63
64# %AVAILABILITY%
65
66# RETURN VALUE
67
68Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
69