Forum Discussion
Switch statement not working
I wrote an iRule and the content is given below. But this is not working as expected.
when HTTP_REQUEST {
if { [HTTP::host] starts_with "abc.com" } {
set var1 "/abc/xyz"
set var2 "/xyz/abc"
switch -glob [HTTP::uri] {
$var1 {
HTTP::redirect "http://www.google.com"
}
$var2 {
HTTP::redirect "http://www.yahoo.com"
}
concat $var1 "mail" {
HTTP::redirect "http://mail.yahoo.co.uk"
}
default {
}
}
}
}
The compilation is successful and no syntax error but the redirections are not happening and always showing "Page not found". But when I converted the above iRule to if elseif statement it started working.
Please let me know what is the issue with the iRule.
- hooleylistCirrostratusHi Sayan,
when RULE_INIT { set var1 "test1" set var2 "test2" switch -glob -- "test1mail" $var1 { log local0. "matched $var1" } $var2 { log local0. "matched $var2" } "${var1}mail" { log local0. "matched ${var1}mail" } default { log local0. "no match" } }
- Yes, I came into that a while back when writing a tech tip. You can omit the curly braces and use a line continuation character to make the switch statement a single line. Otherwise, I haven't found any workaround to this.
Recent Discussions
Related Content
* 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