JSP、PHP、ASP跳轉代碼實現一個網站空間綁定多個域名,建立多個網站

PHP版本

實現方法如下:

先建立一個默認主頁index.php
然後把A站放在A文件夾下
B站放在B文件夾下
C站放在C文件夾下

index.php網頁文件如下

<?php
switch ($_SERVER["HTTP_HOST"])
{
case "www.a.com":
header("location:a/index.php");
break;
case "www.b.com":
header("location:b/index.php");
break;
case "www.c.com":
header("location:c/index.php");
break;
}
?>


如果用戶訪問 www.a.com 程序跳轉至 空間目錄下 a/index.php
如果用戶訪問 www.b.com 程序跳轉至 空間目錄下 b/index.php
如果用戶訪問 www.c.com 程序跳轉至 空間目錄下 c/index.php


利用一個php文件通過瀏覽器輸入的域名,判定他是要打開那個文件夾裏的站點,來實現一個虛擬放置多個站點(缺點例如打開abc.com,在瀏覽器中看到的是abc.com/b因爲站點在b目錄下)

其他說明:如果虛擬主機不支持子目錄綁定,這是唯一有效的辦法



ASP版本

如果只有一個ASP空間,而你又想放置多個多個站點,這些代碼可以幫到你

第一個

程序代碼

<%
if Request.ServerVariables("SERVER_NAME")="www.dzhai.com" then
response.redirect "williamlong/index.htm"
else
response.redirect "index2.htm"
end if
%>

第二個

程序代碼

<%
select case request.servervariables("http_host")
case "www.a.com" '1
Server.Transfer("a.htm")
case "www.b.net" '2
Server.Transfer("b.htm")
case "www.c.com" '3
Server.Transfer("c.htm")
...... 繼續添加 ......
end select
%>


第三個


程序代碼

<%
if instr(Request.ServerVariables("SERVER_NAME"),"www.a.com")>0 then
response.redirect "index.asp"
elseif instr(Request.ServerVariables("SERVER_NAME"),"www.b.net")>0 then
response.redirect "x/index.asp"
elseif instr(Request.ServerVariables("SERVER_NAME"),"www.c.com")>0 then
response.redirect "index3.asp"
end if
%>


第四個


程序代碼

<%
if Request.ServerVariables("SERVER_NAME")="www.a.com" then
response.redirect "index1.asp"
elseif Request.ServerVariables("SERVER_NAME")="www.b.net" then
response.redirect "index2.asp"
elseif Request.ServerVariables("SERVER_NAME")="www.c.com" then
response.redirect "index3.asp"
end if
%>

第五個


程序代碼

<%
if Request.ServerVariables("SERVER_NAME")="www.a.com" then
Server.Transfer("williamlong.htm")
elseif Request.ServerVariables("SERVER_NAME")="www.b.net" then
Server.Transfer("moon.htm")
elseif Request.ServerVariables("SERVER_NAME")="www.c.com" then
Server.Transfer("write100.htm")
else
Server.Transfer("other.htm")
end if
%>


JSP版本

<script>try {if( self.location == "http://玉米一/" ) {
top.location.href = "http://玉米一/目錄";
}
else if( self.location == "http://玉米二/" ) {
top.location.href = "http://玉米二/目錄";
}
else if( self.location == "http://玉米三/" ) {
top.location.href = "http://玉米三/目錄";
}
else if( self.location == "http://玉米四/" ) {
top.location.href = "http://玉米四/目錄";
}
else {document.write ("錯誤的訪問地址")}} catch(e) {}</script>

詳解:

1:首先,你的空間必須支持ASP,並且這個空間可以綁定下面所用到的兩個域名,然後新建一個ASP

的首頁文件,這個ASP文件中的代碼這麼寫:
<%if Request.ServerVariables("SERVER_NAME")="XXXX.cn" then '第一個輸入的網址
response.redirect "index.html"                               '將它轉發到相應的文件夾
else%>

<%end if%>
<%if Request.ServerVariables("SERVER_NAME")="www.XXXX.cn" then response.redirect

"index.html"                
else%>
<%end if%>

<%if Request.ServerVariables("SERVER_NAME")="XXXX.cn" then   '第二個輸入的網址
response.redirect "soft/index.html"                               '將它轉發到相應的文件


else%>

<%end if%>

<%if Request.ServerVariables("SERVER_NAME")="www.XXXX.cn" thenresponse.redirect

"soft/index.html"
else%>

<%end if%>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章