如果只有一個ASP空間,而你又想放置多個多個站點,這些代碼可以幫到你
第一個
程序代碼
<%
if Request.ServerVariables("SERVER_NAME")="theartemis.cn" then
response.redirect "williamlong/index.htm"
else
response.redirect "index2.htm"
end if
%>
第二個
程序代碼
<%
select case request.servervariables("http_host")
case "theartemis.cn" '1
Server.Transfer("v3.htm")
case "Server.Transfer("i.htm")
case "Server.Transfer("write100.htm")
...... 繼續(xù)添加 ......
end select
%>
第三個
程序代碼
<%
if instr(Request.ServerVariables("SERVER_NAME"),"theartemis.cn")>0 then
response.redirect "index.html"
elseif instr(Request.ServerVariables("SERVER_NAME")," then
response.redirect "x/index.html"
elseif instr(Request.ServerVariables("SERVER_NAME")," then
response.redirect "index3.html"
end if
%>
第四個
程序代碼
<%
if Request.ServerVariables("SERVER_NAME")="theartemis.cn" then
response.redirect "index1.html"
elseif Request.ServerVariables("SERVER_NAME")="response.redirect "index2.html"
elseif Request.ServerVariables("SERVER_NAME")="response.redirect "index3.html"
end if
%>
第五個
程序代碼
<%
if Request.ServerVariables("SERVER_NAME")="theartemis.cn" then
Server.Transfer("williamlong.htm")
elseif Request.ServerVariables("SERVER_NAME")="Server.Transfer("moon.htm")
elseif Request.ServerVariables("SERVER_NAME")="Server.Transfer("write100.htm")
else
Server.Transfer("other.htm")
end if
%>
這是一段很有用的代碼,和綁定多域名的ASP代碼類似,如果你只有一個PHP空間,而你又想放置多個多個站點,下面這些代碼可以幫到你
第一個:
程序代碼
if($HTTP_HOST=="theartemis.cn"){
Header("Location: moon.htm");
}
elseif($HTTP_HOST=="}
else{
Header("Location: other.htm");
}
第二個:
程序代碼
if($HTTP_HOST=="theartemis.cn"){
require "moon.htm";
}
elseif($HTTP_HOST=="}
else{
require "other.htm";
}
二用JS來實現(xiàn)多域名的跳轉
<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" '將它轉發(fā)到相應的文件夾
else%>
<%end if%> "index.html" <%if Request.ServerVariables("SERVER_NAME")="XXXX.cn" then '第二個輸入的網址 夾 <%end if%> <%if Request.ServerVariables("SERVER_NAME")="
"soft/index.html" <%end if%> 2:寫好后將這個文件存儲為index.asp ,也就是要做你的首頁。不用擔心,這個是不會顯示的。這 個就是自動識別訪問者輸入域名的,然后依據訪問者輸入的地址進行自動跳轉的。跳轉是在瞬間完 成的,你是看不到的。呵呵 3.現(xiàn)在要做的就是把你空間中建立兩個不同的文件夾了,分別做為兩個網站的目錄。比如一個放音 樂的cd文件夾。一個放FLASH動畫的flash夾件夾。里面的內容自己放!
<%if Request.ServerVariables("SERVER_NAME")="
else%>
<%end if%>
response.redirect "soft/index.html" '將它轉發(fā)到相應的文件
else%>
else%>
4.開始上傳剛才做的index.asp文件吧!把index.asp文件上傳到空間根目錄下。
5.去你的空間中將兩個域名都進行綁定好,然后就可以測試了。
如對本文有疑問,請?zhí)峤坏浇涣髡搲?,廣大熱心網友會為你解答!! 點擊進入論壇