Forum Discussion
hooleylist
Mar 25, 2010Cirrostratus
Here is a set of TCL man pages for the 8.4 version of TCL current iRules are based on:
http://www.tcl.tk/man/tcl8.4/TclCmd/contents.htm
And here is the man page for switch:
http://www.tcl.tk/man/tcl8.4/TclCmd/switch.htm
If I understand correctly, you can use a nested switch statement for domain7.com URI checking:
when HTTP_REQUEST {
switch "[string tolower [HTTP::host]]" {
"domain1.com" -
"www.domain1.com" {
HTTP::respond 301 Location "http://domain2.com
}
"domain3.com" -
"www.domain3.com" {
HTTP::respond 301 Location "https://domain3-edit.com
}
"www.domain4.com" {
HTTP::respond 301 Location "http://domain4.com/"
}
"domain5.com" {
HTTP::respond 301 Location "https://domain5-edit.com/"
}
"www.domain6.com" {
HTTP::respond 301 Location "http://domain6.com/"
}
"www.domain7.com" {
HTTP::respond 301 Location "http://domain7.com/"
}
"domain7.com" {
switch -glob "[string tolower [HTTP::uri]]" {
"/security" {
"/security/" -
Exact match for "/security" or "/security/"
HTTP::respond 301 Location "http://domain7.com/ciso/pages/services.aspx"
}
"/urib*" {
URI starts with "/urib"
HTTP::respond 301 Location "http://domain7.com/ciso/pages/urib.aspx"
}
"*uric" {
URI ends with "uric"
HTTP::respond 301 Location "http://domain7.com/ciso/pages/uric.aspx"
}
"*uri[d-f]" {
URI ends with "urid", "urie" or "urif"
HTTP::respond 301 Location "http://domain7.com/ciso/pages/uric.aspx"
}
"*uri?" {
URI ends with "uri" and any other character (which hasn't already been matched like b, c, d-f)
HTTP::respond 301 Location "http://domain7.com/ciso/pages/uric.aspx"
}
}
}
"www.domain8.com" {
HTTP::respond 301 Location "http://domain8.com/"
}
default {
Take some default action?
}
}
}
Note the -glob flag on the URI checking. This allows you to use string patterns in the switch cases as defined in the 'string match' man page:
http://www.tcl.tk/man/tcl8.4/TclCmd/string.htmM35
string match ?-nocase? pattern string
See if pattern matches string; return 1 if it does, 0 if it doesn't. If -nocase is specified, then the pattern attempts to match against the string in a case insensitive manner. For the two strings to match, their contents must be identical except that the following special sequences may appear in pattern:
*
Matches any sequence of characters in string, including a null string.
?
Matches any single character in string.
[chars]
Matches any character in the set given by chars. If a sequence of the form x-y appears in chars, then any character between x and y, inclusive, will match. When used with -nocase, the end points of the range are converted to lower case first. Whereas {[A-z]} matches '_' when matching case-sensitively ('_' falls between the 'Z' and 'a'), with -nocase this is considered like {[A-Za-z]} (and probably what was meant in the first place).
\x
Matches the single character x. This provides a way of avoiding the special interpretation of the characters *?[]\ in pattern.
Aaron