一个空间绑定多个域名实现自动跳转的几种方法!
给出我自己使用的代码,比如:我有域名1;域名2!
我想域名直接访问blog/index.php
域名2只访问首页index1.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/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>
</html>
即可实现!
本人只是菜鸟,如果不对之处,请大家口下留情!
第一个
程序代码
<%
if Request.ServerVariables("SERVER_NAME")="www.1xx.com" then
response.redirect "williamlong/index.htm"
else
response.redirect "index2.htm"
end if
%>
第二个
程序代码
<%
select case request.servervariables("http_host")
case "www.1xx.com" '1
Server.Transfer("v3.htm")
case "www.2xx.com" '2
Server.Transfer("i.htm")
case "www.3xx.com" '3
Server.Transfer("write100.htm")
...... 继续添加 ......
end select
%>
第三个
程序代码
<%
if instr(Request.ServerVariables("SERVER_NAME"),"www.1xx.com")>0 then
response.redirect "index.asp"
elseif instr(Request.ServerVariables("SERVER_NAME"),"www.2xx.com")>0 then
response.redirect "x/index.asp"
elseif instr(Request.ServerVariables("SERVER_NAME"),"www.3xx.com")>0 then
response.redirect "index3.asp"
end if
%>
第四个
程序代码
<%
if Request.ServerVariables("SERVER_NAME")="www.1xx.com" then
response.redirect "index1.asp"
elseif Request.ServerVariables("SERVER_NAME")="www.2xx.com" then
response.redirect "index2.asp"
elseif Request.ServerVariables("SERVER_NAME")="www.3xx.com" then
response.redirect "index3.asp"
end if
%>
第五个
程序代码
<%
if Request.ServerVariables("SERVER_NAME")="www.1xx.com" then
Server.Transfer("williamlong.htm")
elseif Request.ServerVariables("SERVER_NAME")="www.2xx.com" then
Server.Transfer("moon.htm")
elseif Request.ServerVariables("SERVER_NAME")="www.3xx.com" then
Server.Transfer("write100.htm")
else
Server.Transfer("other.htm")
end if
%>
这是一段很有用的代码,和绑定多域名的ASP代码类似,如果你只有一个PHP空间,而你又想放置多个多个站点,下面这些代码可以帮到你
第一个:
程序代码
if($HTTP_HOST=="www.1xx.com"){
Header("Location: moon.htm");
}
elseif($HTTP_HOST=="www.2xx.com"){
Header("Location: williamlong.htm");
}
else{
Header("Location: other.htm");
}
第二个:
程序代码
if($HTTP_HOST=="www.1xx.com"){
require "moon.htm";
}
elseif($HTTP_HOST=="www.2xx.com"){
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.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%>
2:写好后将这个文件存储为index.asp ,也就是要做你的首页。不用担心,这个是不会显示的。这
个就是自动识别访问者输入域名的,然后依据访问者输入的地址进行自动跳转的。跳转是在瞬间完
成的,你是看不到的。呵呵
3.现在要做的就是把你空间中建立两个不同的文件夹了,分别做为两个网站的目录。比如一个放音
乐的cd文件夹。一个放FLASH动画的flash夹件夹。里面的内容自己放!
4.开始上传刚才做的index.asp文件吧!把index.asp文件上传到空间根目录下。
5.去你的空间中将两个域名都进行绑定好,然后就可以测试了。