Created
October 4, 2014 03:19
-
-
Save JingwenTian/b639dba3200880b48eea to your computer and use it in GitHub Desktop.
这个还可以实现比如jingwentian.com跳转到www.jingwentian.com上,也就是让所有的页面都用带www的网址
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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")//判断是不是首页,or $the_url=="" | |
{ | |
$the_url="";//如果是首页,赋值为空 | |
} | |
if($the_host !== 'www.jingwentian.com')//如果域名不是带www的网址那么进行下面的301跳转 | |
{ | |
header('HTTP/1.1 301 Moved Permanently');//发出301头部 | |
header('Location:http://www.jingwentian.com'.$the_url);//跳转到带www的网址 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment