Forum Discussion
C_D_18583
Nimbostratus
Aug 04, 2005IRule and Error Checking
Please See comments below
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/channel/" } {
pool QA1
}
elseif {[HTTP::uri] starts_with "/performance/" } {
pool QA2
}
elseif { [HTTP::uri] starts_with "/lead/" } {
pool QA3
}
Please review the irule
I want the user to end the URI with /. If this is not done, I need
to redirect the request with the "/" at the end.
The statement below does NOT
work. What is the best way to write this.
elseif { not[HTTP::uri] ends_with "/" } {
HTTP::redirect "https://[HTTP::host][HTTP::uri]/"
}
else {
discard
}
}
- It seems that the ends_with operator isn't returning a boolean value (or at least that's what is being inserted into the logs) can't use non-numeric string as operand of "!"
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/channel/" } { pool QA1 } elseif {[HTTP::uri] starts_with "/performance/" } { pool QA2 } elseif { [HTTP::uri] starts_with "/lead/" } { pool QA3 } elseif { [string index [HTTP::uri] end] ne "/" } { HTTP::redirect "https://[HTTP::host][HTTP::uri]/" } else { discard } }
- unRuleY_95363Historic F5 AccountThis is caused by something called operator precedence. The "not" operator (an alias for "!") is of higher precendence than starts_with, ends_with or equals. So, what's happening is that the not is being applied to the [HTTP::uri] operand and then the result of that is being checked whether it ends_with "/". Clearly not what you want.
elseif { not ( [HTTP::uri] ends_with "/" ) } { HTTP::redirect "https://[HTTP::host][HTTP::uri]/" }
- C_D_18583
Nimbostratus
Thanks Joe , Your solution works! I will also try the other suggestion from unRuleY
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