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 π₯
CURLINFO_REDIRECT_COUNT(3)CURLINFO_REDIRECT_TIME_T(3)CURLOPT_FOLLOWLOCATION(3)curl_easy_getinfo(3)curl_easy_setopt(3)
mwah π this page is brought to you by libcurl, dated 2026-10-12 β CURLINFO_REDIRECT_URL(3), signing off! π«Ά
π¦ where this page comes from
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms