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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值