Canonical Hostname Redirect (non-www to www)

Discussion in 'Search Engine Optimization' started by justAdream, Oct 19, 2009.

  1. #1
    Please help me, how i can customize this code because not works like this
    -------------------------------------
    <%
    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("REQUEST_URI")
    Response.End
    End if
    %>
    ------------------------------

    or please give me some tips for Canonical Hostname Redirect (non-www to www)

    IIS - asp
     
    justAdream, Oct 19, 2009 IP
  2. TheCrabb

    TheCrabb Peon

    Messages:
    304
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    That is asp code so make sure you page has a .asp extension (not .html or .php or .aspx or anything else).
     
    TheCrabb, Oct 19, 2009 IP
  3. justAdream

    justAdream Active Member

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #3
    thank you but also the file extension "asp"

    i get 500 internal server error
     
    justAdream, Oct 19, 2009 IP
  4. monfis

    monfis Well-Known Member

    Messages:
    1,476
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    160
    #4
    Try this (change to your file extension and domain name).

    RewriteEngine On
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.htm\ HTTP/
    RewriteRule ^index\.htm$ http://[B]www.xxxxx.com/[/B] [R=301,L]
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^xxxxx.com$
    RewriteRule ^(.*)$ http://[B]www.xxxxx.com[/B]/$1 [R=301,L]
     
    monfis, Oct 19, 2009 IP
  5. justAdream

    justAdream Active Member

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #5
    than kyou friend but your code is not for IIS - asp
     
    justAdream, Oct 19, 2009 IP
  6. justAdream

    justAdream Active Member

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #6
    i tried like that;

    <%
    If InStr(Request.ServerVariables("xxxxxxxxxxx.com"),"www") = 0 Then
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location","http://www."
    & Request.ServerVariables("xxxxxxxxxxx.com")
    & Request.ServerVariables("asp")
    End if
    %>

    finanly not worked
     
    justAdream, Oct 19, 2009 IP
  7. theapparatus

    theapparatus Peon

    Messages:
    2,925
    Likes Received:
    119
    Best Answers:
    0
    Trophy Points:
    0
    #7
    500 error almost always puts the error into the webserver's error logs. The error even says that it's doing so. Did you check to see what the issue is?
     
    theapparatus, Oct 19, 2009 IP
  8. webdev007

    webdev007 Active Member

    Messages:
    1,037
    Likes Received:
    13
    Best Answers:
    3
    Trophy Points:
    88
    #8
    try to add the following code and test.

     
    webdev007, Oct 19, 2009 IP
  9. justAdream

    justAdream Active Member

    Messages:
    47
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    93
    #9
    thank you for considiration.. but your code isnt Canonical Hostname Redirect (non-www to www)
     
    justAdream, Oct 20, 2009 IP