Forum Discussion
gbunting
Nimbostratus
Jun 18, 2013Need help creating iRule to do redirects based on uri
Hi,
I need to create an iRule that will match this url:
http://mywebsite.com/SEC+TEST/{x}/{y}.htm
where {x} and {y} can be anything. This should redirect to:
...
Kevin_Stewart
Employee
Jun 19, 2013lindex [split [findstr [string tolower [HTTP::uri]] "/sec+test/" 10 ".htm"] "/"] 1]
[findstr [string tolower [HTTP::uri]] "/sec+test/" 10 ".htm"] - finds the part of the string that STARTS WITH "/sec+test/", skips 10 characters (the length of "/sec+test/"), and ends before ".htm". If the URI was "/sec+test/foo/bar.htm", then this would return "foo/bar".
[split [findstr [string tolower [HTTP::uri]] "/sec+test/" 10 ".htm"] "/"] - splits the returned string into a list, based on the delimiter character "/". in the above string this would produce a list of two values: "foo" and "bar".
[lindex [split [findstr [string tolower [HTTP::uri]] "/sec+test/" 10 ".htm"] "/"] 1] - list extracts the second element from the previously returned list. Lists start with a 0 (zero) index, so the second element is 1. This then returns "bar".
While findstr is an efficient and simple way to extract text from a given string, I must concede that Nitass' scan example is more elegant. If I may Nitass:
{/SEC+TEST/%*[^/]/%[^.].htm}
The percent sign in the TCL scan command is a "conversion specifier". If you include the * star character after the % it means that you DO NOT want to include the next values in the scan. So %*[^/] means to ignore the next set of values that do not (^ means NOT) contain a "/" character - so don't include the value after "/SEC+TEST/" and before the next "/". The next % character and brackets means to capture the next set of values that do not contain a "." period character, so everything after the last "/" and before ".htm".
Nice example, Nitass.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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