用ASP内建对象轻松做网址域名自动跳转

迅恒数据中心

以前域名服务商都有url跳转的功能,但是现在由于政策的问题使得url跳转服务取消了。
那么是不是我们就没法使用url跳转呢?
或者我们想让访问者访问的是www.piis.cn,而不是piis.cn,也就是所有访问piis.cn的自动转到www.piis.cn。那么怎么实现呢。
如果你用的是asp服务器,那么就可以用ASP内建对象Request的ServerVariables集合中的变量来实现。
我们知道 ServerVaribles 集合中有下面几个变量:

----------------------------------------------
server_name 访问服务器所用的域名或ip
url 页面所在链接
----------------------------------------------

那么我们就可以用 Server_Name 来判断访问的域名,并利用response的redirect方法转向到不同的页面。
第一步,我们先实现域名的自动跳转。
在首页顶端加入下面一段代码 

或以下形式的:
一:在空间管理后台“修改网站首页”加上网站首页为1.asp并放在最前面为网站第一首页
二:在空间后台绑上所有域名
三:在你的空间根目录里放上1.asp文件,内容参考如下:
<%if Request.ServerVariables("SERVER_NAME")="www.xhisp.com" then
response.redirect "index.asp"
else%>
<%end if%>
<%if Request.ServerVariables("SERVER_NAME")="www.xhisp.cn" then
response.redirect "index.asp"
else%>
<%end if%>
<%if Request.ServerVariables("SERVER_NAME")="piis.cn" then
response.redirect "piis.asp"
else%>
<%end if%>
<%if Request.ServerVariables("SERVER_NAME")="www.piis.cn" then
response.redirect "xhsip.php"
else%>
<%end if%>
<%if Request.ServerVariables("SERVER_NAME")="2008.piis.cn" then
response.redirect "/2008"
else%>
<%end if%>
<%if Request.ServerVariables("SERVER_NAME")="www.liruotong.org" then
response.redirect "http://tieba.baidu.com/f?kw=%C0%EE%C8%F4%CD%AE"
else%>
<%end if%>

分类:建站知识 百度收录 必应收录