Hi I need help on making a 301 redirect in microsoft server for a static website. I need to redirect http://www.domain.com to http://domain.com but I only have ftp access. Many Thanks
Make a file and include it in the very top of every page. Paste this code in the included file <% If Request.ServerVariables("HTTP_HOST") = "www.domain.com" then Response.Status="301 Moved Permanently" If Request.ServerVariables("SCRIPT_NAME") = "/Index.asp" then Response.AddHeader "Location", "http://domain.com" Else Response.AddHeader "Location", "http://domain.com" & Request.ServerVariables("SCRIPT_NAME") End If End If %> Code (markup):
i tried this and its not working: <% If Request.ServerVariables("HTTP_HOST") = "www.dogcontainment-4less.com" then Response.Status="301 Moved Permanently" If Request.ServerVariables("SCRIPT_NAME") = "/Index.asp" then Response.AddHeader "Location", "http://dogcontainment-4less.com" Else Response.AddHeader "Location", "http://dogcontainment-4less.com" & Request.ServerVariables("SCRIPT_NAME") End If Response.Flush Response.End End If %> Code (markup): What do I miss?
<% If Request.ServerVariables("HTTP_HOST") = "www.dogcontainment-4less.com" then Response.Status="301 Moved Permanently" If Request.ServerVariables("SCRIPT_NAME") = "[COLOR="Red"]/yourmainpage.asp[/COLOR]" then Response.AddHeader "Location", "http://dogcontainment-4less.com" Else Response.AddHeader "Location", "http://dogcontainment-4less.com" & Request.ServerVariables("SCRIPT_NAME") End If Response.Flush Response.End End If %> Code (markup): other than that it should work. What the inner if is doing is checking to see if the user is requesting the index page. In asp index.asp is loaded when loading the domain name, so if you have your main page named anything different then it will make a problem, just use this if its not index.asp... <% If Request.ServerVariables("HTTP_HOST") = "www.dogcontainment-4less.com" then Response.Status="301 Moved Permanently" Response.AddHeader "Location", "http://dogcontainment-4less.com" & Request.ServerVariables("SCRIPT_NAME") Response.Flush Response.End End If %> Code (markup):
The very first line may need to be Response.Buffer=TRUE This is because headers cannot be changed once the response has started unless buffering is on. .