php301跳转代码 实现不带www跳转到带www域名

1、载需程序入口文件加入

/** 跳转到 www domain */
//require_once( dirname(__FILE__) . '/301.php' );

2、新建301.php,复制下面代码

<?php
//取得当前域名
$the_host = $_SERVER['HTTP_HOST'];

//判断地址后面部分
$the_url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';

//将英文字母转成小写
$the_url = strtolower($the_url);

//判断是不是首页
if ($the_url == '/index.php') {
	$the_url = '';
}

//如果域名是不带www的网址那么进行下面的301跳转
if ($the_host == '95its.com') {
	//发出301头部
	header('HTTP/1.1 301 Moved Permanently');

	//跳转到带www的网址
	header('Location:https://www.95its.com'.$the_url);
	exit();
}
?>


© 版权声明
THE END