2022年4月23日星期六

使用首页进行301跳转

PHP代码

<?php
// zd.example.com和example.com跳转到http://example.com:555
$the_host = $_SERVER['HTTP_HOST'];
$request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '';
if(($the_host == 'zd.example.com')or($the_host == 'example.com'))
{
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://zd.example.com:555'.$request_uri);//
}
// tz.example.com 则跳转到http://example.com/tz.php
elseif($the_host =="tz.example.com")
{
header("HTTP/1.1 301 Moved Permanently");
Header("Location: http://example.com/tz.php");
}
// 其他则跳转到404页面
else
{
Header("Location: /404.html");
}
?>

HTML代码

<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type ="text/javascript">
document.location.href="http://" + document.location.hostname +":555";
</script>
<head>
<title>document.location</title>
</head>
<body>
<div class="landing-navigation-tablet-top-adjustment"></div>
<a href="http://zd.example.com:555" target="_blank">
<font color=orange size="6px">如果没有跳转请点击(</font></center></a><br>
</a>
</body>
</html>