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; } ?>
如果用户访问 http://www.a.com 程序跳转至 空间目录下 a/index.php
如果用户访问 http://www.b.com 程序跳转至 空间目录下 b/index.php
如果用户访问 http://www.c.com 程序跳转至 空间目录下 c/index.php
利用一个php文件通过浏览器输入的域名,判定他是要打开那个文件夹里的站点,来实现一个虚拟放置多个站点
缺点:例如打开abc.com,在浏览器中看到的是abc.com/b因为站点在b目录下
其他说明:如果虚拟主机不支持子目录绑定,这是唯一有效的办法
ASP版:(准备工作同上)
index.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%>
或
<% 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" end if %>
或
<% if Request.ServerVariables("SERVER_NAME")="www.dzhai.com" then Server.Transfer("williamlong.htm") elseif Request.ServerVariables("SERVER_NAME")="www.6id.net" then Server.Transfer("moon.htm") elseif Request.ServerVariables("SERVER_NAME")="www.write100.com" then Server.Transfer("write100.htm") else Server.Transfer("other.htm") end if %>
JSP版:(准备工作同上)
index.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>