登陆

二级域名绑定目录方法

WBB2015-03-281484人围观 ,发现0个评论

前几天购买了个程序,发现这个程序不用再网站目录下直接就可以绑定二级域名。最后了解是使用的js跳转的。

二级域名绑定目录方法(一):

二级域名绑定的方法非常之简单,在域名设置的A记录下,设置好域名如x.123.com绑定ip先,然后到服务器相关目录下绑定域名x.123.com即可。这是传统的方法。

另外一种方法就是判断来源,访问相应目录,用js、asp、php代码实现。

JS实现多域名同一空间不同目录的代码: 包括了asp、php、js各种形式(二)。
   <script language=javascript> 
      url=window.location.href 
      if(url.indexOf("201job.com")!=-1) 
      location="fs" 
      if(url.indexOf("fs.201job.com")!=-1) 
      location="xinhuirc" 
      if(url.indexOf("www.xinhuirc.com")!=-1
      location="index.html" 
   </script>   
php实现多域名同一空间不同目录的代码: 
<?php 
$domain1="201job.com"; 
$domain2="fs.201job.cn"; 
$domain3="www.xinhuirc.com"; 
$dot1="index.php"; 
$dot2="movie"; 
$dot3="blog"; 
if(($HTTP_HOST=="$domain1")or($HTTP_HOST=="www.$domain1")) 

Header("Location: $dot1"); 

elseif(($HTTP_HOST=="$domain2")or($HTTP_HOST=="www.$domain2")) 

Header("Location: $dot2"); 
}
else(($HTTP_HOST=="$domain3")or($HTTP_HOST=="www.$domain3")) 

Header("Location: $dot3"); 
}  
?> 
JSP实现多域名同一空间不同目录的代码: 
<SCRIPT>try { if( self.location == "http://www.201job.com/" ) { 
top.location.href = "http://www.201job.com/";
}
else if( self.location == "http://www.xinhuirc.com/" ) { 
top.location.href = "http://www.xinhuirc.com/job";
}
else if( self.location == "http://fs.201job.com/" ) { 
top.location.href = "http://fs.201job.com/job";
}
else { document.write ("404.html") } } catch(e) { }</SCRIPT> 
ASP实现多域名同一空间不同目录的代码:
解决方案一(case) 
<% 
host=lcase(request.servervariables("HTTP_HOST")) 
Select CASE host 
CASE "www.201job.com
response.redirect"index.html" 
CASE "201job.com" 
response.redirect"index.html" 
CASE "www.xinhuirc.com
response.redirect"movie/" 
CASE "xinhuirc" 
response.redirect"movie/" 
CASE "fs.201job.com" 
response.redirect"blog/" 
CASE "cothurn.com" 
response.redirect"blog/" 
CASEELSE 
response.redirect"404.html" 
END Select 
%> 
解决方案二(if) 
<%if Request.ServerVariables("SERVER_NAME")="www.201job.com" then
response.redirect "index.html"
elseif Request.ServerVariables("SERVER_NAME")="www.xinhuirc.com"
response.redirect "movie"
else Request.ServerVariables("SERVER_NAME")="fs.201job.com"
response.redirect "blog"
end if%> 
解决方案三(Transfer)完全隐藏式,这个很好 
<%
select case request.servervariables("http_host")
case "www.201job.com" '1
Server.Transfer("index.html")
case "www.xinhuirc" '2
Server.Transfer("movie")
case "fs.201job.com" '3
Server.Transfer("blog")
end select
%> 
解决方案四(instr) 
<%if instr(Request.ServerVariables
("SERVER_NAME"),"201job.com")>0 then
response.redirect "index.html"
elseif instr(Request.ServerVariables
("SERVER_NAME"),"xinhuirc")>0 then
response.redirect "movie"
else instr(Request.ServerVariables
("SERVER_NAME"),"201job.com")>0 then
response.redirect "blog"
end if
%> 

方法来源:http://blog.163.com/dollare@126/blog/static/36611490201221393429612/

请发表您的评论
不容错过
Powered By Z-BlogPHP