Forum Discussion
Substring syntax in iRules
if { [string length [substr [HTTP::uri] 0 "?"]] > 0 }
IN an above statement I can't able to understand what is the purpose of [ Substr 0 "?" ].
give some suggestion or basic idea about that
thanks
- David_Scott_104Historic F5 Account
substr will get at part of a string, the first argument is the string to look at, the second argument specifies how many characters to skip over (0 meaning don't skip any) and the last argument is the terminator or where to stop the substring.
For an example of the parameters, say you have the following url
So the HTTP::uri would be "/downloads?v13"
If I put this in an iRule:
log local0. "[substr [HTTP::uri] 0 "?"] "
Will return everything up to the ? so "/downloads" would be returned.
So in /var/log/ltm you would see something similar to this:
Mar 31 09:59:34 ltm2 info tmm1[11931]: Rule /Common/test : /downloads
Hope that helps you a bit,
Dave
- HectormNimbostratus
looking at your rule if{[string length [substr {HTTP::uri] 0 "?"]]>0} this rule is always going to be true since the first character on a HTTP::uri is always "/" therefore the string lengh will always be greater than 0 may be you want to do if{[string length [substr {HTTP::uri] 1 "?"]]>0} this will start the string length after the first character of HTTP::uri which is always "/"
set VAR1 "/downloads/hector/file1?V12" set VAR2 [substr [VAR1] 0 "?"]
set VAR3 "/downloads/hector/fil?v13?hello" set VAR4 [substr [VAR1] 0 "?"]
set VAR5 [[substr [VAR1] 5 "?"]
- CharlesCSCirrus
In this context, wouldn't
return the same thing and be more efficient?HTTP::path
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
command will extract portion from the beginning of the[substr]
until the first ocourence of a question mark. This will be always at least a[HTTP::uri]
char, which would then resolve to a/
value of at least[string length]
.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