如何为域或主页差异创建301重定向

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何为域或主页差异创建301重定向相关的知识,希望对你有一定的参考价值。

Learn how to create a 301 redirect for domain or home variations to improve your websites' search engine optimization.
  1. '301 Redirect - URL Must Contain www.domain.com
  2. CorrectDomain = "www.domain.com"
  3. DefaultPage = "/index.asp"
  4. QueryStrings = request.ServerVariables("QUERY_STRING")
  5. URL = request.ServerVariables("URL")
  6.  
  7. if instr(request.ServerVariables("SERVER_NAME"),CorrectDomain) = 0 then
  8.  
  9. if QueryStrings <> "" then
  10. QueryStrings = "?" &amp; QueryStrings
  11. end if
  12.  
  13. if instr(URL,DefaultPage) then
  14. URL = replace(URL,DefaultPage,"/")
  15. end if
  16.  
  17. response.Status = "301 Moved Permanently"
  18. response.AddHeader "Location","http://" &amp; CorrectDomain &amp; URL &amp; QueryStrings
  19. response.End
  20.  
  21. end if

以上是关于如何为域或主页差异创建301重定向的主要内容,如果未能解决你的问题,请参考以下文章

301重定向没有片段[重复]

使用 301 重定向重定向 404 是将现有页面重定向到主页

ASP.NET IIS7 的永久 301 重定向

301 从带有 GET 参数的 URL 重定向到主页

301 将带有特殊字符的 URL 重定向到主页 htaccess

Nginx:404错误时返回301重定向