网络营销电子商务研究中心

网络营销电子商务研究中心 (https://www.0058.net/index.php)
-   代码交流 (https://www.0058.net/forumdisplay.php?f=16)
-   -   一个空间绑多个域名的方法 (https://www.0058.net/showthread.php?t=3086)

car 2008-02-25 08:35 PM

一个空间绑多个域名的方法
 
多个域名绑一个空间方法(ASP、PHP、JSP), 一个空间绑多个域名的方法

ASP
第一步:创建转向控制页面
  创建网站默认的首页文件(通常为"index.asp"或"default.asp")如下:

<%
'取得HTTP输入的值并付值到HTOST中
host=lcase(request.servervariables("HTTP_HOST"))
'开始条件跳转
select CASE host
' 如果HOST的值是www.abc0.com就选择事件case"www.abc0.com"的命令
CASE "www.abc0.com"
' Below is the redirect command
response.redirect "index_abc0.asp"
CASE "www.abc1.com"
' Below is the redirect command
response.redirect "index_abc1.asp"
CASE "www.abc2.com"
' Below is the redirect command
response.redirect "index_abc2.asp"
' 继续添加...
CASE "www.abcn.com"
' Below is the redirect command
response.redirect "index_abcn.asp"

'We use CASE ELSE to fix any other requests
CASE ELSE
response.redirect "default.asp"
END select
%>

  第二步:创建相应的被转向文件
  创建"index_abc0.asp"—"index_abcN.asp",作为各个网站的首页。

  第三步:将多个域名的IP地址解析到同一个网站空间
  例如:将"www.abc1.com"—"www.abcN.com"的IP地址全部解析到"www.abc1.com"的WEB空间上。

  第四步:设置网站的WEB服务
  设置WEB服务的别名为:"www.abc1.com www.abc2.com www.abc3.com ...... www.abcN.com"(注意:别名之前用一个空格分开)

  现在你就可以使用象"http://www.abc1.com"、……、"http://www.abcN.com"这类顶级的网址来访问同一个WEB空间,而得到各不相同的首页面了。

JSP
<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
$domain_net="abc.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");
}
?>

或者

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


All times are GMT +8. The time now is 02:01 AM.

Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.