Forum Discussion
Rajesh_A_142089
Apr 08, 2014Nimbostratus
Remove part of querystring
I want to remove specific key=value pair from the querystring if present
-If my uri is /myuri?mykey=myvalue or /myuri?otherkey=othervalue&mykey=myvalue -I want to rewrite the uri such that I rem...
- Apr 09, 2014
Just one approach;-
when HTTP_REQUEST { if {[URI::query [HTTP::uri]] contains "mykey="} { set newq "" foreach param [split [URI::query [HTTP::uri]] "&"] { if {!($param starts_with "mykey=")} { Build up new query parameter string append newq $param } Add new query portion to path HTTP::uri "[HTTP::path]$newq" } }
nitass
Jun 08, 2014Employee
you may also try HTTP::query. HTTP::query writing data is introduced in 11.5.0.
ID385615 - RFE: Make HTTP::query iRule command support writing data
e.g.
config
[root@ve11a:Active:In Sync] config tmsh list ltm rule qux
ltm rule qux {
when RULE_INIT {
set static::qry_name "mykey"
set static::qry_value "myvalue"
}
when HTTP_REQUEST {
log local0. "origin=[HTTP::uri]"
set tmp [string map [list $static::qry_name=[URI::query [HTTP::uri] $static::qry_name] ""] [HTTP::query]]
set tmp [string map {&& &} $tmp]
set tmp [string trimleft $tmp &]
HTTP::query $tmp
HTTP::uri [string trimright [HTTP::uri] ?&]
log local0. "new=[HTTP::uri]"
}
}
test
[root@ve11a:Active:In Sync] config tail -f /var/log/ltm
Jun 8 11:09:21 ve11a info tmm[9801]: Rule /Common/qux : origin=/myuri
Jun 8 11:09:21 ve11a info tmm[9801]: Rule /Common/qux : new=/myuri
Jun 8 11:09:38 ve11a info tmm1[9801]: Rule /Common/qux : origin=/myuri?mykey=myvalue
Jun 8 11:09:38 ve11a info tmm1[9801]: Rule /Common/qux : new=/myuri
Jun 8 11:09:44 ve11a info tmm[9801]: Rule /Common/qux : origin=/myuri?mykey=myvalue&otherkey=othervalue
Jun 8 11:09:44 ve11a info tmm[9801]: Rule /Common/qux : new=/myuri?otherkey=othervalue
Jun 8 11:09:54 ve11a info tmm1[9801]: Rule /Common/qux : origin=/myuri?otherkey=othervalue&mykey=myvalue
Jun 8 11:09:54 ve11a info tmm1[9801]: Rule /Common/qux : new=/myuri?otherkey=othervalue
Jun 8 11:10:03 ve11a info tmm[9801]: Rule /Common/qux : origin=/myuri?otherkey=othervalue&mykey=myvalue&anotherkey=anothervalue
Jun 8 11:10:03 ve11a info tmm[9801]: Rule /Common/qux : new=/myuri?otherkey=othervalue&anotherkey=anothervalue
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