Forum Moderators: open
For example, if you select [yourdomain.com...] as your root page, then if a spider tries to fetch [yourdomain.com...] (without the www), your web server should do a permanent (301) redirect to your root page at [yourdomain.com...]I would like to find out the proper code to use with an .asp or any html site for this 301 redirect so that I can use www.mydomain.com when the bot comes to mydomain.com without the www in front. Can anyone point me in the right direction for this?
strServerName = Request.ServerVariables("SERVER_NAME")
strDomain = "www.example.com"
If Not strServerName = strDomain Then
strRedirectURL = "http://www.example.com" & Request.ServerVariables("URL")
If Request.ServerVariables("QUERY_STRING") <> "" Then
strRedirectURL = strRedirectURL & "?" & Request.ServerVariables("QUERY_STRING")
End If
Response.Status = "301 Moved Permanently"
Response.addheader "Location", strRedirectURL
Response.End
End If