CURLINFO_REDIRECT_URL(3)

πŸ’… CURLINFO_REDIRECT_URL(3) πŸ’…

okay so this one is from the Library Functions Manual, and it is here to spill the redirect tea. It is giving β€œwhere would this redirect even go?” energy. πŸŒ€

✨ NAME ✨

CURLINFO_REDIRECT_URL β€” URL a redirect would go to. No cap. πŸ’«

πŸŽ€ SYNOPSIS πŸŽ€

#include <curl/curl.h>

CURLcode curl_easy_getinfo(CURL *handle, CURLINFO_REDIRECT_URL, char **urlp);

That is the whole vibe: you pass the handle plus this info constant, and you hand over a char ** so it can give you back a URL pointer. 🫢

🌸 DESCRIPTION 🌸

Bestie, here is the deal: you pass a pointer to a char pointer, and it receives the URL that a redirect would take you to if you enabled CURLOPT_FOLLOWLOCATION(3).

This is lowkey handy if you think libcurl’s built-in redirect logic is not good enough for you, but you would still prefer to avoid implementing all the magic of figuring out the new URL yourself. Iconic trade-off, honestly.

Also important: this URL is also set if the CURLOPT_MAXREDIRS(3) limit prevented a redirect to happen (since 7.54.1). So yes, the URL still shows up β€” do not sleep on the parenthetical. 😭

🌈 PROTOCOLS 🌈

This functionality affects http only. That is it, that is the protocol vibe check. 🧚

πŸ’» EXAMPLE πŸ’»

int main(void)
{
  CURL *curl = curl_easy_init();
  if(curl) {
    CURLcode result;
    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
    result = curl_easy_perform(curl);
    if(result == CURLE_OK) {
      char *url = NULL;
      curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &url);
      if(url)
        printf("Redirect to: %s\n", url);
    }
    curl_easy_cleanup(curl);
  }
}

πŸ¦‹ AVAILABILITY πŸ¦‹

Added in curl 7.18.2. So it has been around, but still cute. πŸŽ€

⭐ RETURN VALUE ⭐

curl_easy_getinfo(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK; non-zero means an error occurred β€” see libcurl-errors(3). That is the whole return-value mood. πŸ’…

πŸ”₯ SEE ALSO πŸ”₯


mwah πŸ’‹ this page is brought to you by libcurl, dated 2026-10-12 β€” CURLINFO_REDIRECT_URL(3), signing off! 🫢

πŸ“¦ where this page comes from