Make your request using curl with curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
which will cause curl to follow the redirect.
Then, you can use curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
which will give you the last effective URL that curl fetched.
Alternatively, you can set CURLOPT_FOLLOWLOCATION
to false
, and set CURLOPT_HEADERS
to true
, and parse the redirect location out yourself using a simple regex.