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.
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…
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]
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]