天天看點

一個空間綁定多個域名實作自動跳轉的幾種方法!

如果隻有一個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.dzhai.com" '1

Server.Transfer("v3.htm")

case "www.6id.net" '2

Server.Transfer("i.htm")

case "www.write100.com" '3

Server.Transfer("write100.htm")

...... 繼續添加 ......

end select

第三個

if instr(Request.ServerVariables("SERVER_NAME"),"www.dzhai.com")>0 then

response.redirect "index.asp"

elseif instr(Request.ServerVariables("SERVER_NAME"),"www.6id.net")>0 then

response.redirect "x/index.asp"

elseif instr(Request.ServerVariables("SERVER_NAME"),"www.write100.com")>0 then

response.redirect "index3.asp"

第四個

response.redirect "index1.asp"

elseif Request.ServerVariables("SERVER_NAME")="www.6id.net" then

response.redirect "index2.asp"

elseif Request.ServerVariables("SERVER_NAME")="www.write100.com" then

第五個

Server.Transfer("williamlong.htm")

Server.Transfer("moon.htm")

Server.Transfer("other.htm")

%>

這是一段很有用的代碼,和綁定多域名的ASP代碼類似,如果你隻有一個PHP空間,而你又想放置多個多個站點,下面這些代碼可以幫到你

第一個:

if($HTTP_HOST=="www.dzhai.com"){

Header("Location: moon.htm");

}

elseif($HTTP_HOST=="www.6id.net"){

Header("Location: williamlong.htm");

else{

Header("Location: other.htm");

第二個:

require "moon.htm";

require "williamlong.htm";

require "other.htm";

二用JS來實作多域名的跳轉

<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"                

<%if Request.ServerVariables("SERVER_NAME")="XXXX.cn" then   '第二個輸入的網址

response.redirect "soft/index.html"                               '将它轉發到相應的檔案

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

"soft/index.html"

<%end if%>

2:寫好後将這個檔案存儲為index.asp ,也就是要做你的首頁。不用擔心,這個是不會顯示的。這

個就是自動識别通路者輸入域名的,然後依據通路者輸入的位址進行自動跳轉的。跳轉是在瞬間完

成的,你是看不到的。呵呵

3.現在要做的就是把你空間中建立兩個不同的檔案夾了,分别做為兩個網站的目錄。比如一個放音

樂的cd檔案夾。一個放FLASH動畫的flash夾件夾。裡面的内容自己放!

4.開始上傳剛才做的index.asp檔案吧!把index.asp檔案上傳到空間根目錄下。

5.去你的空間中将兩個域名都進行綁定好,然後就可以測試了。

博文歡迎轉載,但請給出原文連接配接。