In the days of link shorteners and Ajax, there can be many links that ultimately point to the same content. I was wondering what the best way is to get the final, best link for
Using Guzzle (a well known and robust HTTP client) you can do it like that:
addSubscriber($history);
$response = $client->head($url)->send();
if (!$response->isSuccessful()) {
throw new \Exception(sprintf("Url %s is not a valid URL or website is down.", $url));
}
return $response->getEffectiveUrl();
}