Forum Discussion
rdessert_76127
Nimbostratus
Dec 06, 2012Using switch vs if to clean up irule
I'm attempting to clean up an irule that currently uses lots of "if" statements and want to use the "switch" statement instead. I've attempted to format the iRule as follows, but I cannot seem to ge...
Pconlan_71037
Altocumulus
Dec 06, 2012Looks to me like you are missing a closing curly brace after each of the first two switch statements, and an extra one after the last switch statement. Does this work?
when HTTP_REQUEST {
Redirect to www.site.org
switch -glob [string tolower [HTTP::host]] {
"site.org" -
"site.com" -
"www.site.com"
{
HTTP::respond 301 Location "http://www.site.org[HTTP::uri]"
}
}
Match uri patterns and redirect to https
switch -glob [string tolower [HTTP::uri]] {
"/uri1*" -
"/uri2*" -
"/uri3*" -
"/uri4*" -
"/uri5*"
{
log local0.alert "https redirect:[HTTP::host]-[HTTP::uri]-[HTTP::path]"
HTTP::respond 301 Location "https://[HTTP::host][HTTP::uri]"
return
}
}
Match uri's and send traffic to pool
log local0.alert "BEGIN Host:[HTTP::host]-[HTTP::uri]-[HTTP::path]"
switch -glob [string tolower [HTTP::uri]] {
"/" -
"/*" -
"/\\?*" -
"/uri10/*" -
"/uri11/*" -
"/uri12/*" -
"/uri13/*" -
"/uri14/*" -
"/uri15*"
{
log local0.alert "pool1 Host:[HTTP::host]-[HTTP::uri]"
pool pool1
return
}
default {
pool pool2
}
}
}
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