PHP虚拟主机放置多个站点,三种方法实现一个虚拟主机【网站空间】放多个网站...

有些朋友为了省钱需要在一个云虚拟主机上安装多个网站,所以在空间上绑定了好几个域名,但

是访问到的却是相同的内容,怎么样让不同的域名访问不同的内容呢?[虚拟主机本身支

持子目录绑定域名的不在讨论之列]

方法一:(这种方法在网络上使用很普遍)

js实现一个空间安装多个网站的方法

1、在空间上分别绑定 www.wayu.cn和 www.wlxiu.cn

2、把 www.wayu.cn 网站文件传到根目录,把 www.wlxiu.cn 网站传到 ./bbk/ 目录

3、把下面的代码保存为 domain.js ,然后上传到空间根目录

程序代码

switch(location.host){

case 'www.wlxiu.cn:

location.href=http://www.wayu.cn/bbk/

break;

}

1

2

3

4

5

switch(location.host){

case'www.wlxiu.cn:

location.href=http://www.wayu.cn/bbk/

break;

}

4、往空间根目录的首页的

与 之间加入

程序代码

5、当你输入www.wayu.cn 访问看不到任何变化,但是当你输入www.wlxiu.cn 访问,浏览

器自动跳转到 www.wlxiu.cn/bbk/ 。这样便实现了同一个空间安装两个网站了,要实现多

个网站可以依此类推。

方法二:(本人推荐)

用server.Transfer(“”)来实现一个空间多个站的方法

您先将您所有的域名绑定到您的虚拟主机上,然后将虚拟主机根目录中的index.asp

(首页asp文件)里加入下列代码就可以了:

sn=lcase(Request.ServerVariables("SERVER_NAME")) '用于获取用户是通过哪个域名访

问的,并转换成小写

if sn='www.wayu.cn' or sn="5g-yun.com" then server.Transfer("default1.asp")

if sn='www.wlxiu.cn' or sn="wlxiu.cn" then server.Transfer("index.html")

%>

1

2

3

4

5

6

sn=lcase(Request.ServerVariables("SERVER_NAME"))'用于获取用户是通过哪个域名访

问的,并转换成小写

if sn='www.wayu.cn' or sn="5g-yun.com" then server.Transfer("default1.asp")

if sn='www.wlxiu.cn'orsn="wlxiu.cn"thenserver.Transfer("index.html")

%>

看明白了吧,如果访问者输入的域名是www.wayu.cn或wayu.cn的话,就访问

default1.asp页面,如果是用wlxiu.cn或www.wlxiu.cn的话就调用index.html文件。

网上还有一些教程是让您用response.redirect来实现转向,但在这里,我建议您使

用server.Transfer(“”)来实现这个功能,好处有以下几个方面:

1、不会出现页面跳转,直接输入网址后,网址后不会带任何文件,访问者不会看出

你的两个网站是放在同一虚拟主机上。

2、server.Transfer(“”)不会阻挡搜索引擎对你的网站的收录,而

response.redirect可不一定

方法三:(最方便管理,一个空间放的站越多越推荐,本人也经常这样做。)

我的方法是利用一个asp文件通过浏览器输入的域名,判定他是要打开那个文件夹里的站

点,来实现一个虚拟放置多个站点(缺点例如打开abc.com,在浏览器中看到的是

abc.com/b因为站点在b目录下)

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

实现方法如下

可以这样,你先建立一个默认主页index.asp

然后把

A站放在A文件夹下

B站放在B文件夹下

C站放在C文件夹下

index.asp网页文件如下

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

1

2

3

4

5

6

7

8

9

response.redirect"a/index.asp"

elseifRequest.ServerVariables("SERVER_NAME")="www.b.com "then

response.redirect"b/index.asp"

elseifRequest.ServerVariables("SERVER_NAME")="www.c.com "then

response.redirect"c/index.asp"

else

response.redirect"aaa/index.asp"

endif%>

如果用户访问 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个站,并且利于网站管

理,这样做可以根据文件夹名,就知道这个是哪个站。

f40d0e0521b1d9eb757922363a5e691b.png

如果你和我一样抠门,只有一个空间,但是你又想绑定多个域名,建多个独立的站点,现在我就让你的幻想成为现实!

如果只有一个ASP空间,而你又想放置多个多个站点,这些代码可以帮到你

第一个

程序代码

if Request.ServerVariables("SERVER_NAME")="www.wayu.cn" then

response.redirect "index.htm"

else

response.redirect "index2.htm"

end if

%>

1

2

3

4

5

6

7

ifRequest.ServerVariables("SERVER_NAME")="www.wayu.cn"then

response.redirect"index.htm"

else

response.redirect"index2.htm"

endif

%>

第二个

程序代码

select case request.servervariables("http_host")

case "www.wayu.cn"

Server.Transfer("index.htm")

case "www.wlxiu.cn"

Server.Transfer("index2.htm")

case "www.2020web.cn"

Server.Transfer("index3.htm")

...... 继续添加 ......

end select

%>

1

2

3

4

5

6

7

8

9

10

11

selectcaserequest.servervariables("http_host")

case"www.wayu.cn"

Server.Transfer("index.htm")

case"www.wlxiu.cn"

Server.Transfer("index2.htm")

case"www.2020web.cn"

Server.Transfer("index3.htm")

......继续添加......

endselect

%>

第三个

程序代码

if instr(Request.ServerVariables("SERVER_NAME"),"0/'>www.wayu.cn")>0 then

response.redirect "index.htm"

elseif instr(Request.ServerVariables("SERVER_NAME"),"0/'>www.wlxiu.cn")>0 then

response.redirect "index2.htm"

elseif instr(Request.ServerVariables("SERVER_NAME"),"0/'>www.2020web.cn")>0 then

response.redirect "index3.htm"

end if

%>

1

2

3

4

5

6

7

8

9

ifinstr(Request.ServerVariables("SERVER_NAME"),"0/'>www.wayu.cn")>0then

response.redirect"index.htm"

elseifinstr(Request.ServerVariables("SERVER_NAME"),"0/'>www.wlxiu.cn")>0then

response.redirect"index2.htm"

elseifinstr(Request.ServerVariables("SERVER_NAME"),"0/'>www.2020web.cn")>0then

response.redirect"index3.htm"

endif

%>

第四个

程序代码

if Request.ServerVariables("SERVER_NAME")="www.wayu.cn" then

response.redirect "index.htm"

elseif Request.ServerVariables("SERVER_NAME")="www.wlxiu.cn" then

response.redirect "index2.htm"

elseif Request.ServerVariables("SERVER_NAME")="www.2020web.cn" then

response.redirect "index3.htm"

end if

%>

1

2

3

4

5

6

7

8

9

ifRequest.ServerVariables("SERVER_NAME")="www.wayu.cn"then

response.redirect"index.htm"

elseifRequest.ServerVariables("SERVER_NAME")="www.wlxiu.cn"then

response.redirect"index2.htm"

elseifRequest.ServerVariables("SERVER_NAME")="www.2020web.cn"then

response.redirect"index3.htm"

endif

%>

第五个

程序代码

if Request.ServerVariables("SERVER_NAME")="www.wayu.cn" then

Server.Transfer("index.htm")

elseif Request.ServerVariables("SERVER_NAME")="www.wlxiu.cn" then

Server.Transfer("index2.htm")

elseif Request.ServerVariables("SERVER_NAME")="www.2020web.cn" then

Server.Transfer("index3.htm")

else

Server.Transfer("other.htm")

end if

%>

1

2

3

4

5

6

7

8

9

10

11

ifRequest.ServerVariables("SERVER_NAME")="www.wayu.cn"then

Server.Transfer("index.htm")

elseifRequest.ServerVariables("SERVER_NAME")="www.wlxiu.cn"then

Server.Transfer("index2.htm")

elseifRequest.ServerVariables("SERVER_NAME")="www.2020web.cn"then

Server.Transfer("index3.htm")

else

Server.Transfer("other.htm")

endif

%>

这是一段很有用的代码,和绑定多域名的ASP代码类似,如果你只有一个PHP空间,而你又想放置多个多个站点,下面这些

代码可以帮到你

第一个:

程序代码

if($HTTP_HOST=="www.wayu.cn"){

Header("Location: index.htm");

}

elseif($HTTP_HOST=="www.wlxiu.cn"){

Header("Location: index2.htm");

}

else{

Header("Location: other.htm");

}

1

2

3

4

5

6

7

8

9

if($HTTP_HOST=="www.wayu.cn"){

Header("Location: index.htm");

}

elseif($HTTP_HOST=="www.wlxiu.cn"){

Header("Location: index2.htm");

}

else{

Header("Location: other.htm");

}

第二个:

程序代码

if($HTTP_HOST=="www.wayu.cn"){

require "index.htm";

}

elseif($HTTP_HOST=="www.wlxiu.cn"){

require "index2.htm";

}

else{

require "other.htm";

}

1

2

3

4

5

6

7

8

9

if($HTTP_HOST=="www.wayu.cn"){

require"index.htm";

}

elseif($HTTP_HOST=="www.wlxiu.cn"){

require"index2.htm";

}

else{

require"other.htm";

}

如果你的空间是纯静态空间,而你又想放置多个多个站点,能不能实现呢?可以的要命,下面这些代码可以帮到你

js实现一个空间安装多个网站的方法

1、 把下面的代码保存为 domain.js ,然后上传到空间根目录

以下是代码片段:

switch(location.host){

case ’www.5g-yun.com’:

location.href="http://www.wayu.cn/index.htm"

case ’www.wlxiu.cn’:

location.href="http://www.wlxiu.cn/index2.htm"

break;

}

1

2

3

4

5

6

7

switch(location.host){

case’www.5g-yun.com’:

location.href="http://www.wayu.cn/index.htm"

case’www.wlxiu.cn’:

location.href="http://www.wlxiu.cn/index2.htm"

break;

}

2、往空间根目录的首页的

与 之间加入

当你输入 www.wayu.cn 访问时看不到任何变化,但是当你输入 www.wlxiu.cn 访问时,浏览器自动跳转到

www.wayu.cn/index2.htm 。 这样便实现了同一个空间安装2个网站了,要实现多个网站可以依此类推。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值