301 Redirects with from NON pretty url's to pretty url's

Discussion in 'C#' started by Hughes1, Apr 2, 2009.

  1. #1
    OK i have a site that i am moving...

    Old URLs are:
    www.domain.com/category.asp?category_id=1
    www.domain.com/category.asp?category_id=2
    www.domain.com/category.asp?category_id=3

    new URLs are
    www.newdomain.com/shop/item1
    www.newdomain.com/shop/item2
    www.newdomain.com/shop/item3

    So i need to write something in asp that will that will 301 redirect
    if url = "?category_id=1" redirect to www.newdomain.com/shop/item1
    if url = "?category_id=2" redirect to www.newdomain.com/shop/item2
    if url = "?category_id=3" redirect to www.newdomain.com/shop/item3
    else redirect to www.newdomain.com/index.asp

    Just so you understand google has indexed all 3 of these examples:
    www.domain.com/category.asp?category_id=1
    www.domain.com/category.asp?category_id=2
    www.domain.com/category.asp?category_id=3

    So, I want a different 301 redirect TO 3 different pages, but the code needs to be embedded on one page:
    if url = "?category_id=1" redirect to www.newdomain.com/shop/item1
    if url = "?category_id=2" redirect to www.newdomain.com/shop/item2
    if url = "?category_id=3" redirect to www.newdomain.com/shop/item3
    else redirect to www.newdomain.com/index.asp


    I have googled this with no luck.
    Thanks for any help
     
    Hughes1, Apr 2, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Something like:
    
    <%
    Dim catId
    catId = Request.QueryString("category_id")
    If catId >= 1 And catId <= 3 Then
    Response.Redirect "http://www.newdomain.com/shop/item" & catId
    Else 
    Response.Redirect "http://www.newdomain.com/index.asp"
    End If
    %>
    
    Code (markup):
    that would be saved to domain.com/category.asp
     
    camjohnson95, Apr 2, 2009 IP
  3. Hughes1

    Hughes1 Active Member

    Messages:
    106
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    73
    #3
    This is what I ended up writing.
    Not sure if it was the best way, but it worked.

    Thanks again for your help, input.

    <%@ Language=VBScript %>
    <%
    DIM strcategory_id
    strcategory_id = Request.QueryString("category_id")
    
    IF strcategory_id = "32" THEN
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location","http://domain.com/shop/Stickers_and_Labels"
    
    ELSEIF strcategory_id = "21" THEN
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location","http://domain.com/shop/CD_and_DVD"
    
    ELSE
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location","http://domain.com"
    
    END IF
    Code (markup):
     
    Hughes1, Apr 3, 2009 IP