多域名解析到同一网站C的php重定向代码

在index.php最前面加上以下代码:

<?php
if(strpos($_SERVER['HTTP_HOST'],'afish.cnblogs.com')===false){
    #header('Location: http://afish.cnblogs.com/');
    echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en">
<head>
<title>afish.cnblogs.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content="afish.cnblogs.com" />
<meta name="description" content="afish.cnblogs.com" />
</head>
<body>
<iframe width="100%" scrolling="no" height="2800" frameborder="0" src="http://afish.cnblogs.com"></iframe>
</body>
</html>';
    exit();
}
?>

若要实现直接跳转,只需将#header('Location: http://afish.cnblogs.com/');前面的#号去掉即可。

若要实现点击链接后再跳转,注释header('Location: http://afish.cnblogs.com/');这一句即可。

 网站C页面head头部添加代码:

<base href="http://afish.cnblogs.com/" target="_parent" />

打完收工!

原文地址:https://www.cnblogs.com/afish/p/4501708.html