% set uri1 "/abc/anythig"
/abc/anythig
% scan $uri1 {/abc/%s} var1
1
% put $var1
anythig
iRules 101 - 16 - Parsing Strings with the TCL Scan Command by Jason Rahm
I want to match on any value @ the Query string “cal”
URI::query
[root@ve11c:Active:In Sync] config tmsh list ltm rule qux
ltm rule qux {
when RULE_INIT {
set uri1 "/abc.aspx?cal=anything"
log local0. "URI is $uri1 and parameter cal value is [URI::query $uri1 cal]"
}
}
[root@ve11c:Active:In Sync] config tail -f /var/log/ltm
Apr 12 15:55:39 ve11c info tmm1[5649]: Rule /Common/qux : URI is /abc.aspx?cal=anything and parameter cal value is anything
Here is an iRule that I shared with a few customers:
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/abc"} {
set path [HTTP::uri]
variable loc marks the "Second" occurrence of a '/'. This will drop /abc
if you want to drop /abc/xyz, locate the "Third" occurence of '/' by changing 1 to 2 at
set loc [string first "/" $path 1]
set path_minus_root [string range $path $loc end]
Note: the value of variable path_minus_root will start with a '/'
HTTP::redirect "https://www.company.com/new_site/qux$path_minus_root"
}
}