tags:

views:

33

answers:

3

Hi, everyone

I have a curl option FOLLOWLOCATION set to 1. If my script is redirected, is there a chance to find out where have it been redirected to?

Thanks in advance

A: 

I think that if you set the FOLLOWLOCATION to 1, it automatically redirects as many times as you need, and you don't get to know the final destination.

But if you want to know for sure, you'll probably need to follow location manually, check for the 'Location' header each round and repeat the request if need be.

Seb
+1  A: 
$ curl -D /dev/stdout -o /dev/null --silent [URL] |grep '^Location:'

Recurse for each value of Location as needed until it is not set in the headers.

amphetamachine
A: 

See curl_easy_getinfo() and the CURLINFO_EFFECTIVE_URL option:

"Pass a pointer to a char pointer to receive the last used effective URL."

Daniel Stenberg