Forum Discussion
URI Manipulation
Hi, I would like to extract part of a URI, from the 5th "/" to the end, for example:
/string1/string2/string3/string4/something/seomethingelse/
should become:
/something/somethingelse
I cannot use one of the string as delimiter, since they change, but for sure they are always 4
I found that this works, but I wonder if there is some solution more "efficient":
set uri [HTTP::uri]
set fields [split $uri "/"]
set num_fields [llength $fields]
set str1 [getfield [HTTP::uri] "/" 2]
set str2 [getfield [HTTP::uri] "/" 3]
set str3 [getfield [HTTP::uri] "/" 4]
set str4 [getfield [HTTP::uri] "/" 5] set newuri ""
set finaluri ""
for {set x 5} {$x<$num_fields} {incr x} {
set newuri /[lindex $fields $x]
set finaluri $finaluri$newuri
Thanks
- Rico
Cirrus
Giorgio,
Here is an iRule I wrote to be a more efficient solution. Based on what I understand, it seems like you simply want to eliminate the first four items of the URI. I found a simple TCL command that will allow you to replace the undesired elements, effectively removing them. This will allow you to create the URI you want in a bit more optimized way. If there is a modification you want or questions about the iRule, I am sure I can help.
when HTTP_REQUEST { set uri_list [split [HTTP::uri] "/"] if {[llength $uri_list] > 5} { set new_uri_list [lreplace $uri_list 0 4 ""] HTTP::uri [join $new_uri_list "/"] } }
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