Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Senior Coder
    Join Date
    Jul 2005
    Location
    UK
    Posts
    1,051
    Thanks
    6
    Thanked 13 Times in 13 Posts

    Conditional Redirect

    I'm trying to redirect any and all URL's containing the query string "query=" to a static page. Can somebody confirm that this is the correct way to do this?

    Code:
    <%
    If(Request.QueryString("query") <> "") then
       Response.Status="301 Moved Permanently"
       Response.AddHeader "Location", http://www.example.com/staticpage.htm
    End If
    %>
    Thanks

  • #2
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Yes you can surely do this way.
    Another way is to use .htaccess file.

  • #3
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That will work if you are looking for a populated querystring variable
    e.g. page.asp?query=123

    It will not simply check for "query=" though.
    If(Request.QueryString("query") <> "") then
    Response.Status="301 Moved Permanently"
    Response.AddHeader "Location", http://www.example.com/staticpage.htm
    End If
    Do you want to check for a blank querystring?
    If so you have the wrong comparison.

    Code:
    If Request.QueryString("query") = "" Then
     'Redirect
    End If
    If you are wanting to redirect all on the inclusion of "query=" then you need to use InStr()

    Code:
    If InStr(Request.ServerVariables("QUERY_STRING"),"query=") Then
     'Redirect
    End If


    Another way is to use .htaccess file.
    You probably wont have much success with .htaccess and ASP.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •