当前位置:文档之家› 一个空间绑定多个域名实现自动跳转的几种方法

一个空间绑定多个域名实现自动跳转的几种方法

一个空间绑定多个域名实现自动跳转的几种方法!给出我自己使用的代码,比如:我有域名1;域名2!我想域名直接访问blog/index.php域名2只访问首页index1.html<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>跳转页面</title></head><script language="javascript">if(location.toString().indexOf("域名1")!= -1){location.href="blog/index.php"}</script><meta http-equiv="refresh" content="1;URL=index1.html" /><body></body>即可实现!本人只是菜鸟,如果不对之处,请大家口下留情!第一个程序代码<%if Request.ServerV ariables("SERVER_NAME")="" thenresponse.redirect "williamlong/index.htm"elseresponse.redirect "index2.htm"end if%>第二个程序代码<%select case request.servervariables("http_host")case "" '1Server.Transfer("v3.htm")case "" '2Server.Transfer("i.htm")case "" '3Server.Transfer("write100.htm")...... 继续添加......end select%>第三个程序代码<%if instr(Request.ServerV ariables("SERVER_NAME"),"")>0 then response.redirect "index.asp"elseif instr(Request.ServerV ariables("SERVER_NAME"),"")>0 then response.redirect "x/index.asp"elseif instr(Request.ServerV ariables("SERVER_NAME"),"")>0 then response.redirect "index3.asp"end if%>第四个程序代码<%if Request.ServerV ariables("SERVER_NAME")="" thenresponse.redirect "index1.asp"elseif Request.ServerV ariables("SERVER_NAME")="" thenresponse.redirect "index2.asp"elseif Request.ServerV ariables("SERVER_NAME")="" thenresponse.redirect "index3.asp"end if%>第五个程序代码<%if Request.ServerV ariables("SERVER_NAME")="" thenServer.Transfer("williamlong.htm")elseif Request.ServerV ariables("SERVER_NAME")="" thenServer.Transfer("moon.htm")elseif Request.ServerV ariables("SERVER_NAME")="" thenServer.Transfer("write100.htm")elseServer.Transfer("other.htm")end if%>这是一段很有用的代码,和绑定多域名的ASP代码类似,如果你只有一个PHP空间,而你又想放置多个多个站点,下面这些代码可以帮到你第一个:程序代码if($HTTP_HOST==""){Header("Location: moon.htm");}elseif($HTTP_HOST==""){Header("Location: williamlong.htm");}else{Header("Location: other.htm");}第二个:程序代码if($HTTP_HOST==""){require "moon.htm";}elseif($HTTP_HOST==""){require "williamlong.htm";}else{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.ServerV ariables("SERVER_NAME")="" then '第一个输入的网址response.redirect "index.html" '将它转发到相应的文件夹else%><%end if%><%if Request.ServerV ariables("SERVER_NAME")="" then response.redirect"index.html"else%><%end if%><%if Request.ServerV ariables("SERVER_NAME")="" then '第二个输入的网址response.redirect "soft/index.html" '将它转发到相应的文件夹else%><%end if%><%if Request.ServerV ariables("SERVER_NAME")="" thenresponse.redirect"soft/index.html"else%><%end if%>2:写好后将这个文件存储为index.asp ,也就是要做你的首页。

不用担心,这个是不会显示的。

这个就是自动识别访问者输入域名的,然后依据访问者输入的地址进行自动跳转的。

跳转是在瞬间完成的,你是看不到的。

呵呵3.现在要做的就是把你空间中建立两个不同的文件夹了,分别做为两个网站的目录。

比如一个放音乐的cd文件夹。

一个放FLASH动画的flash夹件夹。

里面的内容自己放!4.开始上传刚才做的index.asp文件吧!把index.asp文件上传到空间根目录下。

5.去你的空间中将两个域名都进行绑定好,然后就可以测试了。

相关主题