1、這里用到了ASP中的case選擇語句,根據(jù)servervariables("HTTP_HOST")獲取的主機HTTP頭,也就是域名,來判斷需要跳轉(zhuǎn)到哪些目錄中,特別適合于二級域名的網(wǎng)站使用
<%
host=lcase(request.servervariables("HTTP_HOST")) ‘取得HTTP輸入的值并付值到HTOST中
select CASE host ‘設置跳轉(zhuǎn)條件’
CASE "a.ethnicity.cn" ‘如果HOST的值是 a.ethnicity.c 就選擇case"a.ethnicity.c"的命令訪問/a目錄下站點’
response.redirect "/a/"
CASE "b.ethnicity.cn"
response.redirect "/b/"
case "c.ethnicity.cn"
Server.Transfer("b/default.asp") ‘如果不在上述特定范圍’
CASE ELSE
response.redirect "/else/" ‘轉(zhuǎn)到else目錄’
END select
%>
案例二:php語言,php語言可以對應的是輕云服務器linux的php或者普通的虛擬主機的linux系統(tǒng)
1、PHP 跳轉(zhuǎn)代碼實現(xiàn)一個網(wǎng)站空間綁定多個域名,建立多個網(wǎng)站
switch ($_SERVER["HTTP_HOST"])
{
case "a.ethnicity.cn":
header("location:a/");
break;
case "b.ethnicity.cn":
header("location:b/");
break;
case "c.ethnicity.cn":
header("location:c/");
break;
}
?>
2、key-value的模式
$domain_route = array(
‘a(chǎn).ethnicity.cn’ => ‘a(chǎn)/‘,
‘b.ethnicity.cn’ => ‘b/‘,
‘c.ethnicity.cn’ => ‘c/‘,
‘d.ethnicity.cn’ => ‘main.php’,
);
$domain = $_SERVER[‘HTTP_HOST’];
$target_url = $domain_route[$domain];
header("location:{$target_url}");
?>
友情提醒:虛擬主機因為每個站點性能資源有限,要獲得更好的訪問效果強烈建議一個主機只放置一個站點
如問題還未解決,請聯(lián)系售后技術(shù)支持。