Forum Discussion
Fluidetom_12222
Cirrus
Oct 04, 2013How to use only part of the uri ?
Hey,
I have a very simple iRule to redirect the traffic to another URL if the uri start with a string (in my case "/api").
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/api" } {
...
Kevin_Stewart
Employee
Oct 04, 2013Jurgen abd Samir have good examples. Here's what these might look like:
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/api" } {
set newuri [string range [HTTP::uri] 4 end]
HTTP::redirect "https://service.test.com:7002/Test$newuri"
}
}
or
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/api" } {
set newuri [string map -nocase {"/api" ""} [HTTP::uri]]
HTTP::redirect "https://service.test.com:7002/Test$newuri"
}
}
The most significant difference between these two examples is timing:
% set uri "/api/foo/bar"
/api/foo/bar
% puts [string range $uri 4 end]
/foo/bar
% puts [string map {"/api" ""} $uri]
/foo/bar
% time { set newuri [string range $uri 4 end] } 100000
0.72165 microseconds per iteration
% time { set newuri [string map {"/api" ""} $uri] } 100000
0.80794 microseconds per iteration
The string range command is only slightly faster.
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