Forum Discussion
smp_86112
Cirrostratus
Jun 21, 2010switch statement conditions
Is there a way to configure switch to handle different "conditions"? For example, I want to take one action if [HTTP::uri] equals one string, but a different action if it starts_with another? Schemati...
hoolio
Cirrostratus
Jun 21, 2010Hi SMP,
You can use the -glob flag for wildcard handling with the switch statement. Here are some examples:
when HTTP_REQUEST {
switch -glob [HTTP::uri] {
"/" {
Exact match for /
HTTP::redirect "https://www.myapp.com/somewhere_else"
}
"/custom*" {
URI starts with /custom
HTTP::redirect "http://www.myapp.com/custom"
}
"*gif" -
"*jpg" -
"*css" -
All these cases use the same action.
URI ends with a static file type
pool static_http_pool
}
"/app[0-9]*" {
URI starts with /app where is a digit
HTTP::redirect "https://www.myapp.com/app"
}
"/app?" {
URI starts with /app? where ? is any single character
as /app[0-9]* is before this, ? would be any non-digit character
HTTP::redirect "https://www.myapp.com/app2"
}
default {
No prior match so take some default action
HTTP::redirect "http://www.myapp.com/default"
}
}
}
The glob style matching is the same as with string match. So you can check the string and switch man pages for details:
http://www.tcl.tk/man/tcl8.4/TclCmd/switch.htm
http://www.tcl.tk/man/tcl8.4/TclCmd/string.htm
Aaron
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
