一个空间放多个网站的实现

虚拟主机,虚拟主机上只能有一个默认主页
但是想实现一个虚拟主机上打开多个站点
我的方法是利用一个asp文件通过浏览器输入的域名,判定他是要打开那个文件夹里的站点,来实现一个虚拟放置多个站点(缺点例如打开abc.com,在浏览器中看到的是abc.com/b因为站点在b目录下)

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

实现方法如下

可以这样,你先建立一个默认主页index.asp
然后把A站放在A文件夹下
B站放在B文件夹下
C站放在C文件夹下

index.asp网页文件如下

<%if Request.ServerVariables("SERVER_NAME")="www.a.com " then
response.redirect "a/index.asp"
elseif Request.ServerVariables("SERVER_NAME")="www.b.com " then
response.redirect "b/index.asp"
elseif Request.ServerVariables("SERVER_NAME")="www.c.com " then
response.redirect "c/index.asp"
else
response.redirect "aaa/index.asp"
end if%>

如果用户访问 www.a.com 程序跳转至 空间目录下 a/index.asp
如果用户访问 www.b.com 程序跳转至 空间目录下 b/index.asp
如果用户访问 www.c.com 程序跳转至 空间目录下 c/index.asp
如果用户访问 没有指定的 程序跳转至 空间目录下 aaa/index.asp

怎么样,简单吧。

elseif Request.ServerVariables("SERVER_NAME")="www.b.com " then
response.redirect "b/index.asp"

这段是可以无限复制的哦,一个虚拟主机放几百个站点就是你自己设置的了
只要把域名都绑定在你的虚拟主机上,然后设置这个域名所绑定的站点就OK了

是不是能放100个网站?
要看你的虚拟主机能绑多少个玉米。能绑100个的话当然就能放100个站


程序代码
如果有有一个ASP空间,而你又想放置多个多个站点,这些代码可以帮到你
第一个
<%if Request.ServerVariables("SERVER_NAME")="bbs.along.com.ru" then
response.redirect "bbs"
else
response.redirect "index1.htm"
end if%>

第二个
<%
select case request.servervariables("http_host")
case "www.along.com.ru" ‘1
Server.Transfer("along.htm")
case "www.along.net.ru" ‘2
Server.Transfer("net.htm")
case "www.null.com.ru" ‘3
Server.Transfer("null.htm")
…… 继续添加 ……
end select
%>

第三个
<%if instr(Request.ServerVariables
("SERVER_NAME"),"fjsky.info")>0 then
response.redirect "index.asp"
else if instr(Request.ServerVariables
("SERVER_NAME"),"along.com.ru")>0 then
response.redirect "x/index.asp"
else if instr(Request.ServerVariables
("SERVER_NAME"),"along.net.ru")>0 thenr
esponse.redirect "index3.asp"
end if
end if
end if%>

第四个
<%if Request.ServerVariables("SERVER_NAME")="www.fjsky.info" then
response.redirect "main1.asp"
else if Request.ServerVariables("SERVER_NAME")="fjsky.info" then
response.redirect "main1.asp"
else if Request.ServerVariables("SERVER_NAME")="www.null2.com.ru" then
response.redirect "/web/index.asp"
else if Request.ServerVariables("SERVER_NAME")="null2.com.ru" then
response.redirect "/web/index.asp"
end if
end if
end if
end if%>

第五个
<%
‘取得HTTP输入的值并付值到HTOST中
host=lcase(request.servervariables("HTTP_HOST"))
‘开始条件跳转
Select CASE host
‘ 如果HOST的值是www.iswind.net就选择事件case"www.iswind.net"的命令
CASE "www.abc.net"
‘ Below is the redirect command
response.redirect "web/"
CASE "www.efd.com"
response.redirect "web1/"
‘We use CASE ELSE to fix any other requests
CASE ELSE
response.redirect "web1/"
END Select
%>


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>


php版:
程序代码
<?php
switch ($_SERVER["HTTP_HOST"]) {
case "domain.com":
header("location:blog");
break;
default:
header("location:news");
break;
}
?>

或者

程序代码
<?php
$domain_net="yeahe.com";
$dot_net_url="bbs/";
$dot_com_url="flash";
if(($HTTP_HOST=="$domain_net")or($HTTP_HOST=="www.$domain_net"))
{
Header("Location: $dot_net_url");
}
else
{
Header("Location: $dot_com_url");
}
?>

 

关于浪漫谎言

浪漫谎言,ALLCAN工作室创始人,从事网站开发、网站美工、网络编程等。
此条目发表在PHP分类目录,贴了, , 标签。将固定链接加入收藏夹。

一个空间放多个网站的实现》有1条回应

  1. 嗯不错的方法学习了。

发表评论

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