PHP CURL请求将强制重定向到;www";,直接请求不起作用
出于某种原因,当我在服务器上对测试URL进行CURL调用时,请求会被强制启动到带有“www”的URL。VirtualHost没有任何修改URL的设置,htaccess似乎也没有。在浏览器中直接请求“”时,我会得到实际的页面内容PHP CURL请求将强制重定向到;www";,直接请求不起作用,php,redirect,curl,web,Php,Redirect,Curl,Web,出于某种原因,当我在服务器上对测试URL进行CURL调用时,请求会被强制启动到带有“www”的URL。VirtualHost没有任何修改URL的设置,htaccess似乎也没有。在浏览器中直接请求“”时,我会得到实际的页面内容 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://sub.domain.com/test.html'); curl_setopt($ch, CURLOPT_HEADER, false); curl_seto
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://sub.domain.com/test.html');
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close ($ch);
return varDumpToString($info);
这将返回:
array(22) {
["url"]=>
string(37) "http://sub.domain.com/test.html"
["content_type"]=>
string(29) "text/html; charset=iso-8859-1"
["http_code"]=>
int(301)
["header_size"]=>
int(311)
["request_size"]=>
int(68)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(0)
["redirect_count"]=>
int(0)
["total_time"]=>
float(0.003001)
["namelookup_time"]=>
float(0.000552)
["connect_time"]=>
float(0.002219)
["pretransfer_time"]=>
float(0.002226)
["size_upload"]=>
float(0)
["size_download"]=>
float(331)
["speed_download"]=>
float(110296)
["speed_upload"]=>
float(0)
["download_content_length"]=>
float(331)
["upload_content_length"]=>
float(0)
["starttransfer_time"]=>
float(0.002958)
["redirect_time"]=>
float(0)
["certinfo"]=>
array(0) {
}
["redirect_url"]=>
string(41) "http://www.sub.domain.com/test.html"
}
有什么帮助吗?谢谢。Http代码301表示永久重定向,客户端将根据重定向url发布新请求。您应该检查服务器端的重定向设置。如上所述,没有设置要发生的重定向。尝试从ssh运行“curl-v sub.domain.com”以获取更多信息。似乎“sub.domain.com”解析为“domain.com”的IPv6,该IPv6具有重定向。现在,我不知道为什么子域会重定向到主域,即使sub.domain.com的主机记录已明确设置。这是一个问题,一定是有原因的。不要“思考”或“猜测”一切都是对的。结果显示重定向必须在某个地方重定向请求。我建议仔细检查服务器配置和php代码。是否有主机名验证?按照数据流仔细检查并尽量减少可能发生问题的区域。