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? Schematically, something I'm looking to do something like this:
when HTTP_REQUEST {
switch [HTTP::uri] {
equals "/" { [HTTP::redirect] http://www.myapp.com/somewhere_else }
starts_with "/custom" { [HTTP::uri] "/new" }
}
}
So I'd like a single switch statement look at a string pattern, but take different actions based on the value of different operators.
- hoolio
Cirrostratus
Hi SMP,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" } } }
- smp_86112
Cirrostratus
Thanks hoolio, that does the trick. It would be nice if F5 would add examples like these to their switch wiki page. - hoolio
Cirrostratus
There was an example which used glob style matching on the switch wiki page. I added another example along the lines of the one above. - JRahm
Admin
Thanks Aaron. SMP, As you see examples in the forum threads that show command usage, feel free to add them to the wiki entries. - Ian_SmithRet. Employeethere is also an entire article on various wildcard matches using switch here: http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/244/Switch-Gone-Wild-Using-Wildcards-with-the-Tcl-switch-command.aspx
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