301 redirect non-www to www code issues

Discussion in 'ASP.NET 2.0' started by Nelly, Apr 18, 2010.

  1. Hi

    Ive trawled the forums, google & KB

    I want to add code so that any one who goes to my site non-www will be directed to my site as www.

    I am not a coder, but ive found this snipet of code that actually works:

    <%
    If InStr(Request.ServerVariables("SERVER_NAME"),"www") = 0 Then
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location","http://www." & Request.ServerVariables("HTTP_HOST") & Request.ServerVariables("URL") & "?" & Request.ServerVariables("QUERY_STRING")
    Response.End
    End if
    %>


    Issue(s)

    When I used to go to my site it would show as www.mysite.com AFTER adding the code it shows as www.mysite.com/default.asp?

    If I type http://mysite.com/blue-widgets the address WILL go to the correct page BUT I notice the address bar will be www.mysite.com/404

    Goal

    How can I resolve these issues so that my site home page shows as www.mysite.com and my product page shows correctly in the address bar as www.mysite.com/blue-widgets WITH the new snippet of code installed.

    I assume that some more code is required but after hours of shifting and trying I'm getting nowhere, so help would be very much appreciated.

    More Info that may be useful

    I am no a coder
    asp 1.1
    non iis 7
    default.asp is index page
    snippet added at top of buildpage.asp
    have custom 404 page

    Hope it all helps and that someone can either modify the code or provide a clean bit of code to help me achieve my goal(s), I'm sure its a piece of cake for most coders who contribute to this forum :).

    Thanks in advance

    Nelly
     
  2. Bump!
     
  3. Help Please!
     

Share This Page