PDA

View Full Version : Conditional Redirect



Pennimus
03-23-2007, 02:34 PM
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?



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


Thanks

SSJ
03-24-2007, 09:29 AM
Yes you can surely do this way.
Another way is to use .htaccess file.

degsy
04-18-2007, 04:36 PM
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.



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()



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.