网上找了很多301代码,很多会出现重定向多次,来个简单实用的
$the_host = $_SERVER['HTTP_HOST'];//取得当前域名
$the_url = strtolower($the_host);//将英文字母转成小写
if($the_url=="xxx.com")//判断是不是首页
{
if($_SERVER['REQUEST_URI']=='/'&&$_SERVER['SCRIPT_NAME']=='/index.php'){
header('HTTP/1.1 301 Moved Permanently');//发出301头部
header('Location:https://www.xxx.com');//跳转到带www的网址
}
}