Home  >  Article  >  php教程  >  301页面转向 php,301页面转向

301页面转向 php,301页面转向

WBOY
WBOYOriginal
2016-06-13 08:57:36774browse

301页面转向 php,301页面转向

新建301.php页面,在程序入口文件index.php引用301.php页面

301.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="";//如果是首页,赋值为空
}
if($the_host !== 'www.baidu.com')//如果域名不是带www的网址那么进行下面的301跳转
{
header('HTTP/1.1 301 Moved Permanently');//发出301头部
header('Location:http://www.baidu.com'.$the_url);//跳转到带www的网址
}
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn