Remove www from your url in ASP
Change example.com on line 7 to your domain name. This will do a permanent redirect to the non-www version of your domain. Place this at the top of your file.
So why would I want to do this?
- If you prefer to use the non-www version of your site. (http://example.com)
- Consistent URL referencing is a basic key to good SEO (search engine optimization).
Here is the code below, you will want to place this at the top of your page.
<%
PATH_INFO = lcase(Request.servervariables(“PATH_INFO”))
if PATH_INFO = “/default.asp” then
PATH_INFO = “”
end if
HTTP_HOST = lcase(Request.servervariables(“HTTP_HOST”))
if instr(HTTP_HOST, “www.”) = 1 then
newurl = “http://example.com” & PATH_INFO
Response.Status = “301 Moved Permanently”
Response.AddHeader “Location”, newurl
Response.End
end if
%>
