Forum Discussion

Joe_Pipitone's avatar
Joe_Pipitone
Icon for Nimbostratus rankNimbostratus
Nov 12, 2009

Case insensitive redirects not quite working

I have an iRule that is supposed to do simple redirection if someone types in the following:

http://www.ourdomain.org/LV2010 or http://www.ourdomain.com/lv2010

It seems as though I haven't quite been able to get this to work if I attempt to add anything further past the /LV2010 such as /LV2010/instructors

Can anyone tell me what may be causing this to happen? Here are what the syntax looks like:

 if { [string tolower [HTTP::uri]] starts_with "/lv2010" } {     
        HTTP::redirect "http://www.ourdomain.org/education/display.aspx"    
      } (THIS WORKS)   
      
   if { [string tolower [HTTP::uri]] starts_with "/lv2010/instructors*" } {     
        HTTP::redirect "http://subdomain.ourdomain.org/events/some-other-file-here-2010/speakers/speaker-list.aspx"    
      } (THIS DOES NOT WORK)   
   

Any ideas? These need to be case insensitive as well

9 Replies

  • Also, if I have a rule such as:

     
     if { [string tolower [HTTP::uri]] starts_with "/lv2010/es*" } {   
          HTTP::redirect "http://www.ourdomain.org/education/display.aspx?id=8230"  
        } 
     

    Then this does not work:

     
     if { [string tolower [HTTP::uri]] starts_with "/lv2010/es/qualify" } {   
          HTTP::redirect "http://subdomain.ourdomain.org/events/some-other-file-here-2010/information/qualification.aspx"  
        } 
     
  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    When using the starts_with command you don't need to add an asterisk. It's not a glob style match, the asterisk is implied.

    So you'd want to just use:

     
     if { [string tolower [HTTP::uri]] starts_with "/lv2010/instructors" } {      
       HTTP::redirect "http://subdomain.ourdomain.org/events/some-other-file-here-2010/speakers/speaker-list.aspx"     
     } 
     

    Keep in mind, too, that if you're listing multiple matches you'll want to go from the most specific to the least specific. This is likely why your second post is behaving the way you described. If you match for "/lv2010" then for "/lv2010/es" the first match worked, and the request was already redirected before your second comparison was even performed. If you reverse the order (specific to general) I think you'll see better behavior.

    Colin
  • I stand corrected - the redirects only work in Chrome - not IE or Firefox, is there anything you see wrong?

    Should I be using starts_with in every occurence? I know of an equals and contains?

       if { [string tolower [HTTP::uri]] starts_with "/lv2010/instructors" } {       
        HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/speakers/speaker-list.aspx"      
        } 
        if { [string tolower [HTTP::uri]] starts_with "/lv2010/hotel" } {       
        HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/information/hotel-and-travel.aspx"      
        } 
        if { [string tolower [HTTP::uri]] starts_with "/lv2010/register" } {       
        HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/information/registration.aspx"      
        } 
        if { [string tolower [HTTP::uri]] starts_with "/lv2010/fax" } {       
        HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/information/registration.aspx"      
        } 
        if { [string tolower [HTTP::uri]] starts_with "/lasvegas10" } {       
        HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/home.aspx"      
        } 
        if { [string tolower [HTTP::uri]] starts_with "/lasvegas2010" } {       
        HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/home.aspx"      
        } 
        if { [string tolower [HTTP::uri]] starts_with "/lv2010/es/register" } {       
        HTTP::redirect "http://events.ourdomain.org/events/some-executive-page-2010/information/registration.aspx"      
        } 
        if { [string tolower [HTTP::uri]] starts_with "/lv2010/es/hotel" } {       
          HTTP::redirect "http://events.ourdomain.org/events/some-executive-page-2010/information/hotel-and-travel.aspx"      
        } 
        if { [string tolower [HTTP::uri]] starts_with "/lv2010/es/qualify" } {       
          HTTP::redirect "http://events.ourdomain.org/events/some-executive-page-2010/information/qualification.aspx"      
        } 
        if { [string tolower [HTTP::uri]] starts_with "/lv2010" } {       
          HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/home.aspx"      
        } 
     
  • You might want switch from IF to "switch"

      
        
      switch -glob [string tolower [HTTP::uri]] {  
      "/lv2010/instructors*" { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/speakers/speaker-list.aspx" }  
      "/lv2010/hotel*" { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/information/hotel-and-travel.aspx" }  
      "/lv2010/register*" { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/information/registration.aspx" }  
      "/lv2010/fax*" { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/information/registration.aspx" }  
      "/lasvegas10*" { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/home.aspx" }  
      "/lasvegas2010*" { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/home.aspx" }   
      "/lv2010/es/register*" { HTTP::redirect "http://events.ourdomain.org/events/some-executive-page-2010/information/registration.aspx" }  
      "/lv2010/es/hotel*" { HTTP::redirect "http://events.ourdomain.org/events/some-executive-page-2010/information/hotel-and-travel.aspx" }  
      "/lv2010/es/qualify*" { HTTP::redirect "http://events.ourdomain.org/events/some-executive-page-2010/information/qualification.aspx" }  
      "/lv2010*" { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/home.aspx" }  
      }  
      

    CB

  • FYI this throws an error on the big-ip - i'm using v 9.4.7

     
     switch -glob [string tolower[HTTP::uri]] {  
     

    throws:

     
     01070151:3: Rule [tdwi_caseins_redirects] error: 
     line 4: [wrong  args] [string tolower[HTTP::uri]]