PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

JSP、PHP、ASP跳转代码实现一个网站空间绑定多个域名,建立多个

原创
2016-06-06 19:59:00 1024浏览

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: head

php版本

实现方法如下:

先建立一个默认主页index.php
然后把A站放在A文件夹下
B站放在B文件夹下
C站放在C文件夹下

index.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://玉米一/" ) {<br> top.location.href = "http://玉米一/目录";<br> } <br> else if( self.location == "http://玉米二/" ) {<br> top.location.href = "http://玉米二/目录";<br> } <br> else if( self.location == "http://玉米三/" ) {<br> top.location.href = "http://玉米三/目录";<br> } <br> else if( self.location == "http://玉米四/" ) {<br> top.location.href = "http://玉米四/目录";<br> } <br> else {document.write ("错误的访问地址")}} catch(e) {}</script>

详解:

1:首先,你的空间必须支持ASP,并且这个空间可以绑定下面所用到的两个域名,然后新建一个ASP

的首页文件,这个ASP文件中的代码这么写:
response.redirect "index.html"                               '将它转发到相应的文件夹
else%>


"index.html"                
else%>

response.redirect "soft/index.html"                               '将它转发到相应的文件


else%>

"soft/index.html"
else%>

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。