1. 程式人生 > >php 獲取根域名 並301跳轉www域名

php 獲取根域名 並301跳轉www域名

cati ati php [0 ane eve org permanent 獲取根域名

<?php
$_zjt = $_SERVER[‘HTTP_HOST‘];
$_xxurl = explode(".",$_zjt);
$urlqz = $_xxurl[0];
$_xxurl = array_reverse($_xxurl);
$urlhz = $_xxurl[1].".".$_xxurl[0];
$sssxxxddd = "com.cn|net.cn|org.cn|gov.cn|bj.cn|sh.cn|tj.cn|cq.cn|zj.cn|nm.cn|ln.cn|jl.cn|hl.cn|js.cn|he.cn|ah.cn|fj.cn|jx.cn|sd.cn|ha.cn|hb.cn|hn.cn|gd.cn|gx.cn|hi.cn|sx.cn";
$sssxxxddd = explode("|",$sssxxxddd);
if (in_array($urlhz,$sssxxxddd))
{
$urlhz = $_xxurl[2].".".$_xxurl[1].".".$_xxurl[0];
}

function cw_31(){
global $urlhz;
header("HTTP/1.1 301 Moved Permanently");
header(‘Location: http://www.‘.$urlhz.‘/‘);
exit();
}
if($_zjt==$urlhz){
cw_31();
}
?>

php 獲取根域名 並301跳轉www域名