有些朋友为了省钱需要在一个5G云虚拟主机上安装多个网站 ,所以在空间上绑定了好几个域名,但
是访问到的却是相同的内容,怎么样让不同的域名访问不同的内容呢?[虚拟主机本身支
持子目录绑定域名的不在讨论之列]
方法一:(这种方法在网络上使用很普遍)
js实现一个空间安装多个网站的方法
1、在空间上分别绑定 www.jr160.com和 www.webqp.cn
2 、把 www.jr160.com 网站文件传到根目录 ,把 www.webqp.cn 网站传到 ./bbk/ 目录
3、把下面的代码保存为 domain.js ,然后上传到空间根目录
程序代码
switch(location.host){ case 'www.wlxiu.cn: location.href=https://www.jr160.com/bbk/ break; }
4、往空间根目录的首页的 <head> 与 </head> 之间加入
程序代码
<script language=’javascript’ src=’http://blog.163.com/libin5506@126/blog/domain.js’></script>
5 、当你输入www.jr160.com 访问看不到任何变化,但是当你输入www.webqp.cn 访问 ,浏览
器自动跳转到 www.webqp.cn/bbk/ 。这样便实现了同一个空间安装两个网站了,要实现多
个网站可以依此类推。
方法二:(本人推荐)
用server.Transfer(“ ”)来实现一个空间多个站的方法
您先将您所有的域名绑定到您的虚拟主机上,然后将虚拟主机根目录中的index.asp
(首页asp文件)里加入下列代码就可以了:
<% sn=lcase(Request.ServerVariables("SERVER_NAME")) '用于获取用户是通过哪个域名访 问的 ,并转换成小写 if sn='www.jr160.com' or sn="webqp.cn" then server.Transfer("default1.asp") if sn='www.webqp.cn' or sn="webqp.cn" then server.Transfer("index.html") %>
看明白了吧,如果访问者输入的域名是www.jr160.com或9nqp.com的话,就访问default1.asp页面,如果是用webqp.cn或www.webqp.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网页文件如下
<%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个站,并且利于网站管
理,这样做可以根据文件夹名 ,就知道这个是哪个站。
如果你和我一样抠门,只有一个空间,但是你又想绑定多个域名 ,建多个独立的站点,现在我就让你的幻想成为现实!
如果只有一个ASP空间,而你又想放置多个多个站点 ,这些代码可以帮到你
第一个
程序代码
<% if Request.ServerVariables("SERVER_NAME")="www.jr160.com" then response.redirect "index.htm" else response.redirect "index2.htm" end if %>
第二个
程序代码
<% select case request.servervariables("http_host") case "www.jr160.com" Server.Transfer("index.htm") case "www.webqp.cn" Server.Transfer("index2.htm") case "www.webqp.cn" Server.Transfer("index3.htm") ...... 继续添加 ...... end select %>
第三个
程序代码
<% if instr(Request.ServerVariables("SERVER_NAME"),"0/'>www.jr160.com")>0 then response.redirect "index.htm" elseif instr(Request.ServerVariables("SERVER_NAME"),"0/'>www.webqp.cn")>0 then response.redirect "index2.htm" elseif instr(Request.ServerVariables("SERVER_NAME"),"0/'>www.webqp.cn")>0 then response.redirect "index3.htm" end if %>
第四个
程序代码
<% if Request.ServerVariables("SERVER_NAME")="www.jr160.com" then response.redirect "index.htm" elseif Request.ServerVariables("SERVER_NAME")="www.webqp.cn" then response.redirect "index2.htm" elseif Request.ServerVariables("SERVER_NAME")="www.webqp.cn" then response.redirect "index3.htm" end if %>
第五个
程序代码
<% if Request.ServerVariables("SERVER_NAME")="www.jr160.com" then Server.Transfer("index.htm") elseif Request.ServerVariables("SERVER_NAME")="www.webqp.cn" then Server.Transfer("index2.htm") elseif Request.ServerVariables("SERVER_NAME")="www.webqp.cn" then Server.Transfer("index3.htm") else Server.Transfer("other.htm") end if %>
这是一段很有用的代码,和绑定多域名的ASP代码类似,如果你只有一个PHP空间 ,而你又想放置多个多个站点,下面这些
代码可以帮到你
第一个:
程序代码
if($HTTP_HOST=="www.jr160.com"){ Header("Location: index.htm"); } elseif($HTTP_HOST=="www.webqp.cn"){ Header("Location: index2.htm"); } else{ Header("Location: other.htm"); }
第二个:
程序代码
if($HTTP_HOST=="www.jr160.com"){ require "index.htm"; } elseif($HTTP_HOST=="www.webqp.cn"){ require "index2.htm"; } else{ require "other.htm"; }
如果你的空间是纯静态空间,而你又想放置多个多个站点,能不能实现呢?可以的要命 ,下面这些代码可以帮到你
js实现一个空间安装多个网站的方法
1 、 把下面的代码保存为 domain.js ,然后上传到空间根目录
以下是代码片段:
switch(location.host){ case ’www.jr160.com’: location.href="https://www.jr160.com/index.htm" case ’www.webqp.cn’: location.href="http://www.webqp.cn/index2.htm" break; }
2、往空间根目录的首页的 <head> 与 </head> 之间加入
<script language=’javascript’ src=’http://ssorg.cn/domain.js’></script>
当你输入 www.jr160.com 访问时看不到任何变化,但是当你输入 www.webqp.cn 访问时 ,浏览器自动跳转到
www.jr160.com/index2.htm 。 这样便实现了同一个空间安装2个网站了,要实现多个网站可以依此类推 。
未经允许不得转载! 作者:棋牌源码网,转载或复制请以超链接形式并注明出处棋牌源码网。
原文地址:《三种方法实现一个虚拟主机【网站空间】放多个网站》发布于:2020-11-13
还没有评论,来说两句吧...