使用PHP的重定向代码
新建一个index.php文件,然后参考下面代码按自己的重定向要求做简单修改:
<?php
$the_host = $_SERVER['HTTP_HOST'];
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
switch ($the_host)
{
case "www.iflyhigher.tk":
case "iflyhigher.tk":
$location = "Location: http://igevin.info" . $request_uri;
break;
case "blog.iflyhigher.tk":
$location = "Location: http://blog.igevin.info" . $request_uri;
break;
case "www.moiya.tk":
case "moiya.tk":
$location = "Location: http://igevin.info";
break;
default:
$location = "Location: http://igevin.info";
break;
}
header('HTTP/1.1 301 Moved Permanently');
header($location);
exit();
?>
如果只要对一个域名进行重定向,可以把代码简化成下面的形式:
<?php
$the_host = $_SERVER['HTTP_HOST'];//取得进入所输入的域名
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';//判断后面的请求部分
if($the_host !== 'igevin.info')//igevin.info是我现在的域名
{
header('HTTP/1.1 301 Moved Permanently');//发出301头部
header('Location: http://igevin.info'.$request_uri);//跳转到我的新域名地址
exit();
}
?>
如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!
txttool.com 说一段 esp56物联 查询128 IP查询