Connecting Tech Pros Worldwide Forums | Help | Site Map

select redirect not working

Familiar Sight
 
Join Date: Jul 2006
Posts: 181
#1: Sep 23 '08
Hi, I have this select redirect that doesnt work, only the case else works, anyone see whats wrong with it? Its basically to redirect my dynamic pages to their new homes.
Any help appreciated.
Thanks
Richard


Expand|Select|Wrap|Line Numbers
  1. <%@Language=VBScript%> 
  2.  
  3. <% 
  4. SiteNameURL = Request.ServerVariables("SERVER_NAME") 
  5. %> 
  6.  
  7. <% 
  8. Select Case SiteNameURL 
  9.  
  10. Case "http://www.mysite.com/directory.asp?categoryid=1" 
  11. response.redirect "am-art.asp" 
  12.  
  13. Case "http://www.mysite.com/directory.asp?categoryid=2" 
  14. response.redirect "uf-art.asp" 
  15.  
  16. Case "http://www.mysite.com/directory.asp?categoryid=3" 
  17. response.redirect "uf-art.asp" 
  18.  
  19. Case "http://www.mysite.com/directory.asp?categoryid=4" 
  20. response.redirect "uf-art.asp" 
  21.  
  22. Case "http://www.mysite.com/directory.asp?categoryid=5" 
  23. response.redirect "uf-art.asp" 
  24.  
  25. Case "http://www.mysite.com/directory.asp?categoryid=6" 
  26. response.redirect "uf-art.asp" 
  27.  
  28. Case Else 'redirecting everything other than cases selected above 
  29.  
  30. response.redirect "./" 
  31.  
  32. End Select 
  33.  
  34. %>

DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 930
#2: Sep 24 '08

re: select redirect not working


Hi Richard,

If only your Case Else is being hit then none of your other conditions are being met. I'd comment out the redirect and response.write the value of SiteNameURL to the screen so you can see whether it looks as you'd expect.

Also, as the only difference between the urls is the value of the querystring variable categoryid would it not make sense to test for that rather than the whole address? e.g.

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim iCategoryID
  3. iCategoryID = Request.Querystring("categoryid")
  4.  
  5. Select Case iCategoryID
  6.     Case 1
  7.      'Redirect 1
  8.     Case 2
  9.      'Redirect 2
  10. etc
  11. End Select
  12. %>
  13.  
Let me know if this helps,

Dr B
Familiar Sight
 
Join Date: Jul 2006
Posts: 181
#3: Sep 24 '08

re: select redirect not working


Thanks Dr B, worked perfectly. Basically this for anyone interested is a dynamic redirect that works fine.


Expand|Select|Wrap|Line Numbers
  1. <%@Language=VBScript%> 
  2.  
  3. <% 
  4. Dim iCategoryID 
  5. iCategoryID = Request.Querystring("categoryid") 
  6. Select Case iCategoryID 
  7. case "1" 
  8. Response.Status="301 Moved Permanently"
  9. Response.AddHeader "Location","newaddress.asp"
  10. case "2" 
  11. Response.Status="301 Moved Permanently"
  12. Response.AddHeader "Location","newaddress.asp"
  13. case "3" 
  14. Response.Status="301 Moved Permanently"
  15. Response.AddHeader "Location","newaddress.asp"
  16. case "4" 
  17. Response.Status="301 Moved Permanently"
  18. Response.AddHeader "Location","newaddress.asp"
  19. case "62" 
  20. Response.Status="301 Moved Permanently"
  21. Response.AddHeader "Location","newaddress.asp"
  22. case "5" 
  23. Response.Status="301 Moved Permanently"
  24. Response.AddHeader "Location","newaddress.asp"
  25. case "55" 
  26. Response.Status="301 Moved Permanently"
  27. Response.AddHeader "Location","newaddress.asp"
  28.  
  29. Case Else 'redirecting everything other than cases selected above 
  30.  
  31. response.redirect "./" 
  32.  
  33. End Select 
  34. %>
Reply


Similar ASP / Active Server Pages bytes