实现方法如下:

先建立一个默认主页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目录下)

其他说明:如果虚拟主机不支持子目录绑定,这是唯一有效的办法

本文出自:开源小镇 ww.ostown.cn 转载请注明(谢谢)

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

response.redirect “index1.asp”

elseif Request.ServerVariables(“SERVER_NAME”)=”www.6id.net” then

response.redirect “index2.asp”

elseif Request.ServerVariables(“SERVER_NAME”)=”www.write100.com” 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版本

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

http://www.discuz.net/thread-1186592-1-1.html

赞赏

微信赞赏支付宝赞赏

「赏不在多,觉得文章有用,就赞赏下吧!」

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据