The -glob will give you "globbing" functionality. Not quite regular expressions, but with wildcarding.
The problem with a class approach is that you can't easily do wildcard matching so you'll have to have an entry for each possibility for the domains.
There are two approaches to using classes with redirects.
1) Using classes with each domain and it's redirect
class domain_check {
"www.abc.com http://www.xzy.com/content.cfm?pageid=11049]"
"www.def.com http://www.xzy.com/content.cfm?pageid=11049]"
"www.ghik.com http://www.xzy.com/content.cfm?pageid=11049]"
"www.lmnop.com http://www.xzy.com/content.cfm?pageid=11049]"
"order.ace.com https://catalog.acme.com"
}
--- Begin iRule ---
when HTTP_REQUEST {
set redir [findclass [string tolower [HTTP::host]] $::domain_check " "]
if { $redir ne "" } {
HTTP::redirect "$redir"
}
}
Or, you could use multiple classes along with the match class command and the ends_with operator to give more of a wild-card type approach
class domain_one {
"www.abc.com"
"www.def.com"
"www.ghik.com"
"www.lmnop.com"
}
class domain_two {
"order.ace.com "
}
--- Begin iRule ---
when HTTP_REQUEST {
if { [matchclass [string tolower [HTTP::host]] ends_with $::domain_one] } {
HTTP::redirect "http://www.xzy.com/content.cfm?pageid=11049]"
} elseif { [matchclass [string tolower [HTTP::host]] ends_with $::domain_two] } {
HTTP::redirect "https://catalog.acme.com"
}
}
One final option would be to do a hybrid approach where you externalize the redirect urls.
class domain_check {
"www.abc.com 1"
"www.def.com 1"
"www.ghik.com 1"
"www.lmnop.com 1"
"order.ace.com 2"
}
class redirect_urls {
"1 http://www.xzy.com/content.cfm?pageid=11049]"
"2 https://catalog.acme.com"
}
--- Begin iRule ---
when HTTP_REQUEST {
set redir_idx [findclass [string tolower [HTTP::host]] $::domain_check " "]
if { $redir_idx ne "" } {
set redir [findclass $redir_idx $::redirect_urls " "]
if { $redir ne "" } {
HTTP::redirect "$redir"
}
}
}
Not sure why you would want this level of indirection, but it makes it so if you need to change your redirect urls more often, you only have to change it in one place.
As for optimization, your best bet is to go with the switch approach, then the matchclass, then the first findclass, then the last one. You determine which would work best for your situation.
Good Luck!
-Joe