Forum Discussion
IRULE - Search in http query and set two variables
Good afternoon, sorry for my English.
I need to store two variables from a uniq query. For example:
www.example.com/test.jpg?aserver=2&bserver=3
I need a irule looking aserver value and save in variable val_Aserver. And too looking bserver value and save in another value, val_Bserver .
I've been looking and can not find how to do it.
Right now I have the following code:
set val_Aserver [string range [HTTP::uri] [expr {[string first "aserver=" [HTTP::uri]] + 8}] end]
set val_Bserver [string range [HTTP::uri] [expr {[string first "bserver=" [HTTP::uri]] + 8}] end]
This only just save me the first value that I pass from the query,
If I put www.example.com/test.jpg?aserver=2&bserver=3, correctly save val_Aserver is 2, but the val_Bserver is empty.
If I put www.example.com/test.jpg?bserver=5&aserver=4 , correctly save val_Bserver is 5, but the val_Aserver is empty.
I'm going crazy, someone can help me please?
Thank you very much.
- Arnaud_LemaireEmployee
Hello you can get inspiration from this one : https://devcentral.f5.com/wiki/iRules.URIInterrogation.ashx
when HTTP_REQUEST { set namevals [split [HTTP::query] "&"] for {set i 0} {$i < [llength $namevals]} {incr i} { set params [split [lindex $namevals $i] "="] set pnum [expr $i+1] log local0. "Param\[$pnum\]: [lindex $params 0]" log local0. "Value\[$pnum\]: [URI::query [HTTP::uri] [lindex $params 0]]" } }
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