Forum Discussion
Regular Expression - HTTP URI
How can i match on following :
-http://www.xyz.com/abc/"anything" >>> I want to match on http://www.xyz.com/abc/ with anything after "/abc/"
-http://www.xyz.com/abc/QW"anything" >>> I want to match on http://www.xyz.com/abc/QW with anything after "QW"
-http://www.xyz.com/abc.aspx?cal="anything" >>> I want to match on any value @ the Query string "cal"
2 Replies
- nitass
Employee
I want to match on http://www.xyz.com/abc/ with anything after "/abc/"
I want to match on http://www.xyz.com/abc/QW with anything after "QW"you may try scan command.
% 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
https://devcentral.f5.com/articles/irules-101-16-parsing-strings-with-the-tcl-scan-commandI want to match on any value @ the Query string "cal"
URI::query
https://devcentral.f5.com/wiki/iRules.URI__query.ashx[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
- John_Alam_45640Historic F5 Account
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" } }
You can also do this job using the [URI::path [HTTP::uri]] commands which are very useful.
https://devcentral.f5.com/wiki/iRules.URI.ashx
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