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.

Checking the URL using ASP (not using Request.ServerVariabls)

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

  1. #1
    I want to do something like

    If URL Contains /ProductDetails.asp
    Then
    Redirect
    End If

    I used the code below but it doesn't work perfectly:

    <%
    If Request.ServerVariables("url") = "/ProductDetails.asp" Then
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location", "redirectURL"
    End If
    %>

    The above code seems to check with the server what URL is being called. However, I'm rewriting URLs to make them SEO friendly and the code above won't let me redirect correctly.

    So... my question is... is there a way using ASP that I can check the URL for a string not using the ServerVariables command?
     
    MidoriWeb, Feb 16, 2007 IP
  2. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #2
    try this

    <%
    If instr(Request.ServerVariables("SCRIPT_NAME"), "ProductDetails.asp")>0 Then
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location", "redirectURL"
    End If
    %>
     
    ludwig, Feb 17, 2007 IP
  3. MidoriWeb

    MidoriWeb Member

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Thank you for the reply ludwig.

    I did some reasearch with what you said and it seams if you use instr and > 0 it will scan for whatever you put inside instr and search for that string of text. If it's found, it's given a value of 1, so if it's 1 which is greater then 0, it will do the rewrite. Do I have that right?

    I'll spend some time playing around with your code... but I think it will do exactly what I want. Thanks again :)
     
    MidoriWeb, Feb 23, 2007 IP
  4. ludwig

    ludwig Notable Member

    Messages:
    2,253
    Likes Received:
    66
    Best Answers:
    0
    Trophy Points:
    225
    #4
    yes you got the point

    hope it helped ya

    regs
     
    ludwig, Feb 24, 2007 IP