我正在使用 CURL 来检查 URL 是否存在(HEAD 请求),但是当我用www.google.com
,它将我重定向到www.google.co.uk
- 可能是因为我的服务器位于英国。
有什么办法可以阻止这种情况发生吗?我不想删除CURLOPT_FOLLOWLOCATION
选项,因为这对于 301 重定向等很有用。
我的部分代码如下;
$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']
包含www.google.co.uk
当我设置$url
as www.google.com