【学习】根据不同的域名跳转到指定的位置

 

有些空间不能绑定子目录,这也就意味着这个空间只能做一个网站,但是,有时我们需要做个网站,还想和原来的网站有所区别,那么,你也许会用到下面的这个代码。

根据域名跳转到指定的网址或目录。

如果您的网站是ASP版本的,那么可以使用下面这个。

 

 ======源码开始处 ======
<%  
if Request.ServerVariables("SERVER_NAME")="www.qs5.org" then  
response.redirect "index.html"     
else  
if Request.ServerVariables("SERVER_NAME")="qs5.org" then  
response.redirect "http://www.qs5.org/"     
else  
response.redirect "404.htm"     
end if  
end if  
%>
  ======源码结束处 ======
下面,我来解释下这个代码的使用方法;
if Request.ServerVariables("SERVER_NAME")="www.qs5.org" then
这段代码中的 标红部分为 当域名为 这个时,跳转到下面的内容。
response.redirect "index.html" 
这个内容可以是指定的文件、目录、甚至是域名(注:域名请加http://)
 
而这段代码:
response.redirect "404.htm"  
表示当访问域名域名没有设置时,统一跳转到 404.htm 这个文件。
添加方法:
else if Request.ServerVariables("SERVER_NAME")="域名" then 
response.redirect "跳转到的地址"    
else 
可以增加无数个域名。
同时,每添加一条记录,就在最后的%>前加上一个end if
然后把修改完的代码另存为 index.asp 上传到根目录即可。
PHP版:
 ======源码开始处 ======
<?php 
switch ($_SERVER["HTTP_HOST"]) 
case "qs5.org":  
header("location:www.qs5.org"); 
break; 
case "blog.qs5.org": 
header("location:blog"); 
break; 
case "www.qs5.org": 
header("location:index.html"); 
break; 
case "www.1111.com": 
header("location:www.1111.com"); 
break; 
case "1111.com": 
header("location:1111.html"); 
break; 
?>
 ======源码结束处 ======

 

  1. 没有评论

  1. 没有通告

:56: :55: :54: :53: :52: :51: :50: :49: :48: :47: :46: :45: :44: :43: :42: :41: :40: :39: :38: :37: :36: :35: :34: :33: :32: :31: :30: :29: :28: :27: :26: :25: :24: :23: :22: :21: :20: :19: :18: :17: :16: :15: :14: :13: :12: :11: :10: :09: :08: :07: :06: :05: :04: :03: :02: :01:

无觅相关文章插件,快速提升流量