There was a good contribution to the wiki a while back outlining general guidelines on how to write fast iRules
http://devcentral.f5.com/Wiki/default.aspx/iRules/HowToWriteFastRules.html
Click here
It states in there that switch statements are better than matchclass for 100 items or less. While that may be true, manageability is a major issue to consider. Including everything in a class, especially when you are mapping domains to uris, is much more usable and easy to update.
If I were you, I'd go with the class approach and either with the matchclass or findclass calls (matchclass if you just want to see if an element is present, findclass if you want to extract the element and possible other subcomponents).
This code illustrates how you can embed domains and redirect urls into a class and access them with the findclass command:
class domain_check {
"www.test.com primary.com"
"test.com primary.com"
"www.xyz.com secondary.com"
"xyz.com secondary.com"
}
--- Begin iRule ---
when HTTP_REQUEST {
set redir [findclass [HTTP::host] $::domain_check " "]
if { $redir ne "" } {
HTTP::redirect "http://$redir[HTTP::uri]"
}
}
The findclass will look for the HTTP::host value and return the second token in the list item (separated by spaces).
Your iRule remains quite simple and all your management is done within the data group.
If you have the same domain you are mapping to, just use the matchclass which returns a boolean if a match is found.
-Joe