ASP代码

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

以ASP为例:  

<%if Request.ServerVariables("SERVER_NAME")="www。gzza。com " then  
response.redirect "weba/index.asp"  
elseif Request.ServerVariables("SERVER_NAME")="bbs。gzza。com " then  
response.redirect "webb/index.asp"  
else  
response.redirect "index.asp"  
end if%>

这里有三个域名都绑在同一虚拟空间的IP  
www。gzza。com  
bbs。gzza。com  
she。gzza。com 

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

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

<%
host=lcase(request.servervariables("HTTP_HOST"))
Select CASE host
CASE "www。it000。com"
response.redirect "01/"
CASE "bbs。it000。com"
response.redirect "02/"
CASE ELSE
response.redirect "03/"
END Select
%>

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

PHP代码

<?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");   
?>

标签: none

添加新评论