能够使多域名但是只有一个站点的小站,通过路由访问到各个指定目录
<?php
//域名跳转路由
//默认跳转
$default = "http://www.stanwind.com/index.php";
//自定义域名路由
$routers = array(
"so.stanwind.com" => "http://www.stanwind.com/zzss",
"proxy.stanwind.com" => "http://www.stanwind.com/proxy",
"json.stanwind.com" => "http://www.stanwind.com/json"
);
$currentHost = $_SERVER['HTTP_HOST'];
//echo $_SERVER['HTTP_HOST'];//获取当前域名
$goPage = $default;
if (array_key_exists($currentHost, $routers)) {
$goPage = $routers[$currentHost];
}
if (array_key_exists("QUERY_STRING", $_SERVER) && !empty($_SERVER["QUERY_STRING"])) {
$goPage = $goPage.'?'.$_SERVER["QUERY_STRING"];
}
//echo $_SERVER["QUERY_STRING"];
//echo $goPage;
//重定向浏览器
header("Location: ".$goPage);
//确保重定向后,后续代码不会被执行
exit;