Forum Discussion
Nick_Coelho_338
Nimbostratus
Dec 21, 2006else procedure undefined?
i have what I think is a simple iRule (i am a complete novice mind you). i can not get the else command to work. gives the following eror no matter what i do. sorry if i am just dense
01070151:3: Rule [iRule1] error:
line 32: [undefined procedure: else] [else]
_______________________________________________________________________
iRule:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/affiliates" -
"/endpages" -
"/friends" -
"/images" -
"/img" -
"/inc" -
"/includes" -
"/maintenance" -
"/outage" -
"/popup" -
"/referral" -
"/sc" -
"/servicestudy" -
"/sitemap" -
"/thrivent" -
"/upgrade" -
"/userControls" {
pool Pool1
}
}
else
{HTTP::redirect "http://blahblah.com"}
}
3 Replies
- Deb_Allen_18Historic F5 AccountIn most tcl implementations both braces need to be on the same line with the "else", since the "else" is actually part of the "if" command.
In F5's tcl implementation, the "else" has to be on the same line as the leading brace, but the trailing brace may be on the next line.
Standard tcl syntax:
Alternate F5 syntax:if { condition }{ code } else { code }
And unless your URIs consist only of the specified directories with no trailing path or filename, you will also need to wildcard your switch patterns to get the expected matches:if { condition }{ code } else { code }
HTHwhen HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/affiliates*" - "/endpages*" - "/friends*" - ...
/deb - Deb_Allen_18Historic F5 Account(edited previous post for typos in code example - doh!)
- If what you were trying to do with the else is to provide a "default" clause for the switch statement (ie. everything that doesn't match one of your previous comparisons), then you can make use of the built-in "default" keyword in the switch statement. "else" is part of the "if" clause, not switch.
Oh, and Deb is right that you'll probably want wildcards if you want your comparison to be like the "starts_with" operator.when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/affiliates*" - "/endpages*" - "/friends*" - "/images*" - "/img*" - "/inc*" - "/includes*" - "/maintenance*" - "/outage*" - "/popup*" - "/referral*" - "/sc*" - "/servicestudy*" - "/sitemap*" - "/thrivent*" - "/upgrade*" - "/userControls*" { pool Pool1 } default { HTTP::redirect "http://blahblah.com" } } }
-Joe
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