Forum Discussion
Substring syntax in iRules
Hi Charles,
as already outlined by David, a if { [string length [substr [HTTP::uri] 0 "?"]] > 0 } will make no sense at all, since the used
[substr]
command will extract portion from the beginning of the [HTTP::uri]
until the first ocourence of a question mark. This will be always at least a /
char, which would then resolve to a [string length]
value of at least 1
.
To check if a HTTP query string (the portion after the first
?
character) is present you may use one of the iRule snippets below...
Example1: Using a rather simple
syntax.if { X contain Y } then { }
if { [HTTP::uri] contains "?" } then {
A query string is present
} else {
A query string is NOT present
}
Example2: Using F5s
command to extract the URI query string.[HTTP::query]
if { [HTTP::query] ne "" } then {
A query string is present
} else {
A query string is NOT present
}
Note: The difference of the two syntaxes is, that the first example will also identify empty query strings (e.g.
) and the seconds example will only identify query strings with valid parameters (e.g. /somepath?
)./somepath?param=1
Cheers, Kai
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