自己建站的朋友经常需要各种各样的代码来实现一些个性化需求,比如网址跳转代码,以前本站的文章中也曾经分享过多种不同的跳转代码,不过今天发现的这个跳转效果比较特殊,可以保留二级域名无损跳转,这种跳转方式适用于各类网站,具体使用用途看个人了!
跳转代码如下:
<?php
error_reporting(0);
$domain = 'chukuangren.com';//需要跳转的域名
$host = $_SERVER['HTTP_HOST'];
$dot1 = strpos($host,'.');
$dot2 = strrpos($host,'.');
if($dot1==$dot2){//一级域名
header("Location: http://{$domain}");
}else{//二级域名
$attr = substr($host,0,$dot1);
$location = $attr.'.'.$domain;
header("Location: http://{$location}/");
}
exit;
原文地址:https://www.xuemy.cn/archives/246.html
楚狂人




