301 跳转

发布于:
分类: Script

ASP 中,我们习惯使用 Response.Redirdect 来实现页面的跳转,但是这种跳转方式的状态是 302 的,属于临时跳转,对于搜索引擎来说,是一种不友好的重定向方式。

ASP 3.0 中,有了另一种方式,即 Response.Transfer 。关于这个,可以查询相关的信息。

我们这里要讨论的是 301 跳转,例如下面的代码: 

  1. <%@ Language="VBScript" %>    
  2.   
  3. <%    
  4.   
  5. Response.Status = "301 Moved Permanently"    
  6.   
  7. Response.AddHeader "Location""http://www.cdsc.com.cn"    
  8.   
  9. %>    
  10.   

假设有域名 cdsc.com.cn 和 wetyoier.cn ,分别针对同一个空间中的 cdsc_com.cn 和 wetyoier_cn 两个目录,那么怎么通过两个域名来自动确定访问哪个目录呢?请看下面的代码:

  1. <%    
  2.   
  3. Dim strHost = LCase(Request.ServerVariables("HTTP_HOST"))    
  4.   
  5. Response.Status = "301 Moved Permanently"    
  6.   
  7. Select Case strHost    
  8.   
  9. Case "cdsc.com.cn"    
  10.   
  11. Response.AddHeader "Location",    
  12.   
  13. "http://cdsc.com.cn/cdsc_com.cn/"    
  14.   
  15. Case "wetyoier.cn"    
  16.   
  17. Response.AddHeader "Location",    
  18.   
  19. "http://wetyoier.cn/wetyoier_cn/"    
  20.   
  21. Case Else    
  22.   
  23. Response.AddHeader "Location",    
  24.   
  25. "http://wetyoier.cn/wetyoier_cn/"    
  26.   
  27. End Select    
  28.   
  29. %>   

另外关于这个的应用,就是在音乐播放或者下载中,针对浏览器或客户代理类型进行判断,从而选取对应的操作。例如限制只能使用 FlashGet 下载等等。

留下评论

您的电子邮箱地址不会被公开。 必填项已用 * 标注