一空间放置多网站的转向代码

时间:2009年02月19日作者:青雨被围观 428 次评论次数:0

有时候买一个虚拟空间,足可以放N个站点,一般只要把各站点的对应域名都绑在这个虚拟空间的IP上,然后使用以下代码便可实现空间共享,站点独立 的效果
以ASP为例

代码:
<%if Request.ServerVariables(”SERVER_NAME”)=”www.cnz88.com ” then
response.redirect “weba/index.asp”
elseif Request.ServerVariables(”SERVER_NAME”)=”bbs.cnz88.com ” then
response.redirect “webb/index.asp”
else
response.redirect “index.asp”
end if%>

这里有三个域名都绑在同一虚拟空间的IP
 

www.aa.com 
bbs.bb.com 
she.cc.com 

将以上代码另存为 default.asp 放在站点根目下下(假定站点默认头文档为default.asp) 

如果用户访问 www.aa.com 程序跳转至 空间目录下weba/index.asp 
如果用户访问 bbs.bb.com 程序跳转至 空间目录下webb/index.asp 
如果用户访问 she.cc.com程序跳转至 空间目录下 index.asp

代码:
<%
host=lcase(request.servervariables(”HTTP_HOST”))
Select CASE host
CASE “www.aa.com”
response.redirect “01/”
CASE “bbs.aa.com”
response.redirect “02/”
CASE ELSE
response.redirect “03/”
END Select
%>

假设01/ 02/ 03/ 为不同目录

代码:
<?php
$arrays=array(
’www.aa.com’=>’aa/index.html’,
’www.bb.com’=>’bb/index.html’,
’www.cc.com’=>’cc/index.html’,
’www.dd.com’=>’dd/index.html’,
’127.0.0.1’=>’bbs/index.php’,
);
$url = $arrays[$_SERVER[’HTTP_HOST’]];
Header(”Location: $url”);
标签:,分类:Html/Css
0条评论

暂时没有评论!

发表评论

*

*