php多域名單站點路由
阿新 • • 發佈:2018-12-31
能夠使多域名但是隻有一個站點的小站,通過路由訪問到各個指定目錄
<?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;