301 ASP www. to not redirect - The below code is used to redirect an asp webpage to it's non www. counterpart. It can be easily adapted to do the reverse as well. The code is actually rather simple for asp and once it's figured. I searched online and couldn't find anything that did exactly this so here it is for the next guy.
<%@LANGUAGE="VBSCRIPT" %>
<% Dim Current_page_URL
Current_page_URL = "http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL")
if NOT isNull(Request.ServerVariables("QUERY_STRING")) then
if Request.ServerVariables("QUERY_STRING") <> "" then
Current_page_URL = Current_page_URL & "?" & Request.ServerVariables("QUERY_STRING")
end if
end if
if Current_page_URL <> Replace(Current_page_URL, "http://www.", "http://") then
Current_page_URL = Replace(Current_page_URL, "http://www.", "http://")
Response.Status="301 Moved Permanently"
Response.AddHeader "Location", Current_page_URL
end if
%> |
301 ASP.NET www. to not redirect - This is the asp.net version of the above code. The below code is used to redirect an asp.net webpage to it's non www. counterpart. It can be easily adapted to do the reverse as well. The code is actually rather simple for asp and once it's figured. I searched online and couldn't find anything that did exactly this so here it is for the next guy.
<%@ Page Language="VB" ContentType="text/html" Debug="true" %>
<%@ Register TagPrefix="MM" Namespace="DreamweaverCtrls"
Assembly="DreamweaverCtrls,version=1.0.0.0,publicKeyToken=836f606ede05d46a,culture=neutral" %> <% Dim Current_page_URL Current_page_URL = Request.ServerVariables("SERVER_NAME") + Request.ServerVariables("URL") Dim Query_String_String Query_String_String = Request.QueryString().ToString() if Query_String_String <> "" then Current_page_URL = Current_page_URL + "?" + Query_String_String end if Current_page_URL = "http://" + Current_page_URL if Current_page_URL <> Replace(Current_page_URL,"http://www.","http://") then Current_page_URL = Replace(Current_page_URL,"http://www.","http://") Response.Status = "301 Moved Permanently" Response.AddHeader("Location",Current_page_URL)
end if %> |