1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

My 301 redirect isn't working...

Discussion in 'C#' started by MidoriWeb, Feb 15, 2007.

  1. #1
    I want to redirect users from my dynamic URL to my static URL. The code I'm trying to use is the following:

    <%
    If Request.ServerVariables("url") = "/ProductDetails.asp" Then
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location", """/"" & replace(replace(replace(RS_Product.Fields(""ProductNameShort""), "" "", ""_""), ""."", ""_""), ""!"", """") & ""_p/"" & RS_Product.Fields(""ProductCode"") & "".htm"""
    End If
    %>

    But that code is pulling up this URL:

    /%22/%22%20&%20replace(replace(replace(RS_Product.Fields(%22ProductNameShort%22),%2 0%22%20%22,%20%22_%22),%20%22.%22,%20%22_%22),%20%22!%22,%20%22%22)%20&%20%22_ p/%22%20&%20RS_Product.Fields(%22ProductCode%22)%20&%20%22.htm%22)

    Is it possible to do what I'm attempting? If it is... what do I need to change in my current code to get this working?

    I should probably note... my dynamic URL would be something like:

    /ProductDetails.asp?ProductCode=pcode1

    My static URL of that same page would be:

    /*ProductNameShort*_p/pcode1.htm

    My site takes the short product name, replaces spaces with underscores (along with other characters with blanks or underscores), and outputs like the URL shown above.

    I'm placing my redirect on my ProductDetails.asp. So when the page is called, it should be able to pull details from my database like ProductNameShort and pcode.

    For example... on my site... I'm using the following code to link to my static URL:

    <a href="<%=SEOImage("/" & replace(replace(replace(RS_Product.Fields("ProductNameShort"), " ", "_"), ".", "_"), "!", "") & "_p/" & RS_Product.Fields("ProductCode") & ".htm")%>">

    That code works and shows a link to the correct static product page. But... I can't seem to modify the above code to get that working inside my 301 redirect.

    Any help would be appreciated.
     
    MidoriWeb, Feb 15, 2007 IP
  2. MidoriWeb

    MidoriWeb Member

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #2
    I thought about doing something like this (it doesn't work... but it might be easier then what I was doing):

    <%
    Dim redirectURL
    redirectURL = SEOImage("/" & replace(replace(replace(RS_Product.Fields("ProductNameShort"), " ", "_"), ".", "_"), "!", "") & "_p/" & RS_Product.Fields("ProductCode") & ".htm")
    If Request.ServerVariables("url") = "/ProductDetails.asp" Then
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location", "redirectURL"
    End If
    %>

    I just need to find a way to make my redirectURL text located in Response.AddHeader actually call the variable I created. Not sure how to do that though :)
     
    MidoriWeb, Feb 15, 2007 IP
  3. MidoriWeb

    MidoriWeb Member

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Figured it out... needed to remove the quotes from my variable :)
     
    MidoriWeb, Feb 16, 2007 IP