Forum Discussion
Irule issue for if statement error
Hello folks
need help on below , i am getting undefined procedure in line3 and missing script after if error line 2
when HTTP_REQUEST { if { ([HTTP::uri] contains "/dfg") and !([matchclass [IP::remote_addr] equals IP_Range]) } { HTTP::redirect "https://abc.com" } pool ab-Pool }
any help appreciated
2 Replies
- VernonWells
Employee
It's likely caused by the way the rule is flattened. When I create a rule as follows on 11.5.3, it works fine:
when HTTP_REQUEST { if { ([HTTP::uri] contains "/dfg") and !([matchclass [IP::remote_addr] equals IP_Range]) } { HTTP::redirect "https://abc.com" } pool ab-Pool }Newlines (and semi-colons) are statement delimiters in Tcl, and somewhat counter-intuitively,
is a command in Tcl, as isif
. Therefore, thepool
is one statements, and theif { ... } { ... }
in another.pool ...Having said that, note that
is deprecated, as explained here:matchclassYou should use
, instead.class matchMoreover, the
command at the end is essentially a noop if you assigned that pool to the associated Virtual Server. Assuming this is the only iRule associated with the VS, you should remove thepool
command, and if you've not done so already, assign the pool to the VS. It is clearer and more performant.pool - VernonWells
Employee
The syntax is essentially the same:
if { [class match [IP::remote_addr] equals IP_Range] } { ... }(assuming that IP_Range is the name of the data-group.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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