How To Create A 301 Redirect For Domains Or Home Page Variances


/ Published in: ASP
Save to your folder(s)

Learn how to create a 301 redirect for domain or home variations to improve your websites' search engine optimization.


Copy this code and paste it in your HTML
  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

URL: http://www.nealgrosskopf.com/tech/thread.asp?pid=22

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.