I am using CURL to check for the existence of a URL (HEAD request) but when I test it with www.google.com
, it redirects me to www.google.co.uk
- probably because my server is UK-based.
Is there a way you can stop this from happening? I don't want to remove the CURLOPT_FOLLOWLOCATION
option as this is useful for 301 redirects etc.
Part of my code is below;
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FORBID_REUSE, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
$output = curl_exec($ch);
// get data
$data = curl_getinfo($ch);
$data['url']
contains www.google.co.uk
when I set $url
as www.google.com
Try accessing
www.google.com/ncr
, it'll avoid the redirect to the .co.uk (or any other national) page.