Forum Discussion

Pete_Paiva_7147's avatar
Pete_Paiva_7147
Icon for Nimbostratus rankNimbostratus
Mar 26, 2007

Modify iRule to ignore case sensitivity in URI

Here's my current iRule:

 

 

when HTTP_REQUEST {

 

set uri [HTTP::uri]

 

if { $uri contains "/crn" } {

 

 

pool pdam.com-HTTP

 

 

} elseif { $uri contains "/dmz0431993" } {

 

 

pool www.domain.com-8683

 

 

} elseif { $uri contains "/dmz0431994" } {

 

 

pool www.domain.com-8683_appserv2

 

 

}

 

}

 

 

I'd like to setup it to ignore case sensitivity. In other words accessing http://www.domain.com/crn or http://www.domain.com/CRN would send me to the same pool. Same would also apply to the /dmz or /DMZ. Can someone please help.

 

 

Thanks,

 

-Pete

6 Replies

  • The builtin TCL "string tolower" command should do what you want.

    when HTTP_REQUEST {
      set uri [string tolower [HTTP::uri]]
      if { $uri contains "/crn" } {
        pool pdam.com-HTTP
      } elseif { $uri contains "/dmz0431993" } {
        pool www.domain.com-8683
      } elseif { $uri contains "/dmz0431994" } {
        pool www.domain.com-8683_appserv2
      }
    }

    A couple of comments on your iRule.

    If you are using the contains operator, then any string match within the URI will get picked up regarless of if it's the first on (ie. /crn, /foo/crn). From your example, it's implied, that you are comparing the first part of the URI. If so, you might want to use the "starts_with" operator in place of "contains".

    Also, here's an alternate approach to your iRule using a switch statement (switch statements are a touch faster than if/elseifs.

    when HTTP_REQUEST {
      switch -glob [string tolower [HTTP::uri]] {
        "/crn*" {
          pool pdam.com-HTTP
        }
        "/dmz0431993*" {
          pool www.domain.com-8683
        }
        "/dmz0431994*" {
          pool www.domain.com-8683_appserv2
      }
    }

    This is analogous to your previous iRule with the "starts_with" operator. If you want to make it like a "contains" comparison, just prepend each string match with another "*".

    Probably more info than you wanted, but oh well, it's Monday...

    -Joe
  • When I tried the switch command exactly as you explained it gave me an error message

     

    01070151:3: Rule [Test123-redirect] error: line 4: [wrong args] [switch [string ToLower [HTTP::uri]]{ ] line 4: [invalid option "ToLower" must be: bytelength compare equal first index is last length map match range repeat replace tolower totitle toupper trim trimleft trimright wordend wordstart] [ToLower]

     

    Any idea?

     

  • 01070151:3: Rule [Test123-redirect] error: line 4: [wrong args] [switch [string ToLower [HTTP::uri]]{ ] line 4: [invalid option "ToLower" must be: bytelength compare equal first index is last length map match range repeat replace tolower totitle toupper trim trimleft trimright wordend wordstart] [ToLower]

     

    it is tolower (not ToLower).

     

  • I did and it still did not work.

     

    Do I need the * after the matching pattern"/dmz0431994*"?

     

  • I did and it still did not work.

     

    what error did you get? can you post the irule?

     

    Do I need the * after the matching pattern"/dmz0431994*"?

     

    no. the pattern looks correct to me.