Forum Discussion
CSA
Nimbostratus
Oct 29, 2012Smartest way to do a class lookup case insensitive
Hi,
Everything is in the title.
I'd like to use class lookup (or a class match -value as it's the same) in a case insenstive way. There isn't any "-nocase" option like in some other class commands.
Basically, I have a datagroup for URL redirections (many "http://www.a.com/b" := "http://www.c.com/d") and I want the URL redirections to be case insensitive.
Thanks!
8 Replies
- What_Lies_Bene1
Cirrostratus
You'll want to use the stringtolower command, more info here: https://devcentral.f5.com/tutorials/tech-tips/irules-101-13-tcl-string-commands-part-1 - nitass
Employee
e.g.[root@ve10:Active] config b virtual bar list virtual bar { snat automap pool foo destination 172.28.19.79:80 ip protocol 6 rules myrule profiles { http {} tcp {} } } [root@ve10:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { set host [HTTP::host] set uri [HTTP::uri] if { [class match -- "http://[string tolower $host$uri]" equals redirection_class] } { HTTP::redirect [class match -value "http://[string tolower $host$uri]" equals redirection_class] } } } [root@ve10:Active] config b class redirection_class list class redirection_class { "http://www.a.com/b" { "http://www.c.com/d" } } [root@ve10:Active] config curl -I http://172.28.19.79/b -H "Host: www.a.com" HTTP/1.0 302 Found Location: http://www.c.com/d Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve10:Active] config curl -I http://172.28.19.79/B -H "Host: www.A.com" HTTP/1.0 302 Found Location: http://www.c.com/d Server: BigIP Connection: Keep-Alive Content-Length: 0
- nitass
Employee
i think this could be a bit better.when HTTP_REQUEST { set host [string tolower [HTTP::host]] set uri [string tolower [HTTP::uri]] if { [class match -- "http://$host$uri" equals redirection_class] } { HTTP::redirect [class match -value "http://$host$uri" equals redirection_class] } }
- CSA
Nimbostratus
Thanks all for your answers. - hoolio
Cirrostratus
If you can't/don't want to guarantee that the data group entries are in lower case, you could loop through each data group element name and set it to lowercase for comparison or use string match -nocase. However, the overhead for the looping should be higher than using a native class command with string tolower on the input string. - nitass
Employee
e.g.[root@ve10:Active] config b virtual bar list virtual bar { snat automap pool foo destination 172.28.19.79:80 ip protocol 6 rules myrule profiles { http {} tcp {} } } [root@ve10:Active] config b rule myrule list rule myrule { when HTTP_REQUEST { set result [lindex [class get -nocase redirection_class "http://[HTTP::host][HTTP::uri]"] 1] if { $result ne "" } { HTTP::redirect $result } } } [root@ve10:Active] config b class redirection_class list class redirection_class { "http://www.A.com/B" { "http://www.c.com/d" } } [root@ve10:Active] config curl -I http://172.28.19.79/b -H "Host: WWW.a.com" HTTP/1.0 302 Found Location: http://www.c.com/d Server: BigIP Connection: Keep-Alive Content-Length: 0 [root@ve10:Active] config curl -I http://172.28.19.79/somethingelse -H "Host: www.domain.com" HTTP/1.1 404 Not Found Date: Tue, 30 Oct 2012 01:55:58 GMT Server: Apache/2.2.3 (CentOS) Content-Type: text/html; charset=iso-8859-1
- CSA
Nimbostratus
Interesting solution, I'm going to give it a try! - hoolio
Cirrostratus
That's novel Nitass. Nice solution.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects