Reputation: 8602
What is the best method to find where a URL redirects to?
If using cURL CURLOPT_FOLLOWLOCATION
will follow every header. What I am looking to do is just find the next location?
My first idea was to use cURL but disable FOLLOWLOCATION and then parse the result for Location: XXXX
but I was thinking there must be a more efficient way.
Upvotes: 0
Views: 240
Reputation: 437386
You can set CURLOPT_MAXREDIRS
(see manual) to 1 along with CURLOPT_FOLLOWLOCATION
.
However, note that unless combined with CURLOPT_HEADER
, this will result in grabbing the contents of the resource being redirected to. You don't want to do that just to find where the redirect goes.
For all that it's worth, IMO in this situation it would be better and very comparable complexity-wise to parse the Location
header of the response instead.
Upvotes: 2