判断是否为某个域名后跳转
$yuming = isset($_SERVER['HTTP_X_FORWARDED_HOST']) ? $_SERVER['HTTP_X_FORWARDED_HOST'] : (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : '');//获取当前域名 $the_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; if($yuming !== 'www.shiguan6.com')//如果域名不是带www的网址那么进行下面的301跳转 { header('HTTP/1.1 301 Moved Permanently');//发出301头部 header('Location:http://www.shiguan6.com'.$the_url);//跳转到带www的网址 }
直接跳转
Header("HTTP/1.1 301 Moved Permanently"); Header("Location: http://www.shiguan6.com");