I have to get the final redirect url from the this: https://web.archive.org/web/20070701005218/http://www.maladnews.com/ which actually redirects to this: https://web.archive.org/web/20080109064420/http://www.maladnews.com/Site%203/Malad%20City%20&%20Oneida%20County%20News/Malad%20City%20&%20Oneida%20County%20News.html
I tried the answers from other stackoverflow answers which works for other websites but not for the above link.
I've tried to extract regular location header:
if(preg_match('#Location: (.*)#', $html, $m))
$l = trim($m[1]);
and also checked the javascript way:
preg_match("/window\.location\.replace\('(.*?)'\)/", $html, $m) ? $m[1] : null;
Please help!
Use
curl_getinfo()
withCURLINFO_REDIRECT_URL
orCURLINFO_EFFECTIVE_URL
depending on your use case.-- http://php.net/manual/en/function.curl-getinfo.php
Example:
When I run this code, the output is: