Forum Discussion
C_D_18583
Nimbostratus
Nov 03, 2005String Manipulation
I have the following piece of code in my iRule
elseif { $uri starts_with "/nexus/" } {
pool pool1 }
elseif { $uri starts_with "/earth/" } {
pool poo...
Nov 04, 2005
getfield should get you where you want to go. You can use getfield to extract a specified field from a string. Using a slash as a delimiter and selecting field 2 you can get the first value after the slash in the URI.
This will get you the token without the slashes. You can check for the existence of a "." at that point but you won't be able to see if it ended with a slash. I'd suggest for that check you rescan the URI for the extracted token with a slash appended to it.
So, something like this should work:
Extract first element after slash in URI
set f [getfield [HTTP::uri] "/" 2]
Check if field contains doesn't contain a dot
and if the uri doesn't contain the field followed by a slash
if { not ($f contains ".")
and not ([HTTP::uri] contains "${f}/") } {
Perform redirect.
HTTP::redirect "http://[HTTP::host]/${f}/"
}
You could possibly use HTTP::uri in the redirect with a slash appended. That should produce the same result.
*Standard disclaimer: this iRule hasn't been tested...
-Joe
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