asp 404 error page question

J

JPElectron

I'm looking for a way to redirect based on when more than one condition is
met, I think I proably need some if/then statements? Can someone provide a
sample code or point me in the right direction...

Here's what I've got:

<%
Dim sScriptname, sRedirect
sScriptname = LCase(Request.ServerVariables("QUERY_STRING"))
response.write sScriptname
Select Case True
Case Instr(sScriptname, "392x72") > 0
sRedirect = "/392x72.htm"
Case Instr(sScriptname, ".htm") > 0
sRedirect = "/404.htm"
Case Instr(sScriptname, ".gif") > 0
sRedirect = "/blank.gif"
Case Instr(sScriptname, ".jpg") > 0
sRedirect = "/blank.jpg"
Case Instr(sScriptname, ".swf") > 0
sRedirect = "/blank.swf"
Case Else
sRedirect = "/ohcrap.htm"
End Select

Response.Redirect sRedirect
%>

What I'd really like to happen here is if "392x72" -and- ".gif" are found
then redirect to 392x72.gif and if "392x72" -and- ".htm" are found then
redirect to 392x72.htm Is this possible?

Thanks very much in adavnce, I'm new to this.
 
S

Steven Burn

Can't personally see anything wrong with what you have already, but you may
get a little better functionality if you change;

Instr(sScriptname, The_Ext) > 0

to

Instr(1, sScriptname, The_Ext, vbTextCompare) > 0


lord knows why, but, using it as you have, always seems to cause problems
for me, so started opting the for latter instead.
--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!
 
E

Evertjan.

JPElectron wrote on 12 mei 2004 in
microsoft.public.inetserver.asp.general:
<%
Dim sScriptname, sRedirect
sScriptname = LCase(Request.ServerVariables("QUERY_STRING"))
response.write sScriptname
Select Case True
Case Instr(sScriptname, "392x72") > 0
sRedirect = "/392x72.htm"
Case Instr(sScriptname, ".htm") > 0
sRedirect = "/404.htm"
Case Instr(sScriptname, ".gif") > 0
sRedirect = "/blank.gif"
Case Instr(sScriptname, ".jpg") > 0
sRedirect = "/blank.jpg"
Case Instr(sScriptname, ".swf") > 0
sRedirect = "/blank.swf"
Case Else
sRedirect = "/ohcrap.htm"
End Select

Response.Redirect sRedirect
%>

What I'd really like to happen here is if "392x72" -and- ".gif" are
found then redirect to 392x72.gif and if "392x72" -and- ".htm" are
found then redirect to 392x72.htm Is this possible?

o Do not use case, unless you know very well what you are doing.
o Do not do a response.write before a redirect, it does not work.
o Else clauses after a redirect are not necessary.
Try:

<%
sSn = LCase(Request.ServerVariables("QUERY_STRING"))

If Instr(sSn,"392x72")>0 AND Instr(sSn,".gif")>0 Then
Response.Redirect "/392x72.gif"
End If

'' If Instr(sSn,"392x72")>0 AND Instr(sSn,".htm")>0 Then
'' Not needed, is taken care of by the next clause

If Instr(sSn,"392x72")>0 Then
Response.Redirect "/392x72.htm"
End If
If Instr(sSn,".htm")>0 Then
Response.Redirect "/404.htm"
End If
If Instr(sSn,".gif")>0 Then
Response.Redirect "/blank.gif"
End If
If Instr(sSn,".jpg")>0 Then
Response.Redirect "/blank.jpg"
End If
If Instr(sSn,".swf")>0 Then
Response.Redirect "/blank.swf"
End If

Response.Redirect "/ohcrap.htm"
%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top