Forum Discussion
BigIP_Support_9
Nimbostratus
Nov 17, 2005forward URI with manipulation
We have an application with several modules for each dept. Each module is handled by a dedicated server. The application use URI to identify the module:
http://www.abc.com/sales/func1/index.jsp (w...
Nov 17, 2005
This is actually easier than it sounds. You can use the standard TCL string command (Click here) to extract everything including and past the second slash. Then use the HTTP::uri command to change the URI. I'm sure there are other ways to do this but this should work for you.
Also, In 9.x we support elseif's which should make your code a bit cleaner.
when HTTP_REQUEST {
strip first directory from uri.
ie. /foo/bar/foobar.ext -> /bar/foobar.ext
set sub_uri [string range [HTTP::uri] [string first {/} [HTTP::uri] 1] end]
if { [HTTP::uri] starts_with "/sales" } {
pool sales_pool
HTTP::uri $sub_uri
} elseif { [HTTP::uri] starts_with "/cs" } {
pool cs_pool
HTTP::uri $sub_uri
} else {
do something else
}
}
Here are the docs for the string commands I'm using.
string first string1 string2 ?startIndex?
Search string2 for a sequence of characters that exactly match the characters in string1. If found, return the index of the first character in the first such match within string2. If not found, return -1. If startIndex is specified (in any of the forms accepted by the index method), then the search is constrained to start with the character in string2 specified by the index.
string range string first last
Returns a range of consecutive characters from string, starting with the character whose index is first and ending with the character whose index is last. An index of 0 refers to the first character of the string. first and last may be specified as for the index method. If first is less than zero then it is treated as if it were zero, and if last is greater than or equal to the length of the string then it is treated as if it were end. If first is greater than last then an empty string is returned.
Here's a break down of the command
set sub_uri [string range [HTTP::uri] [string first {/} [HTTP::uri] 1] end]
is equivalent to:
Find index of first slash searching from position 1 (2nd char)
set idx [string first {/} [HTTP::uri] 1]
Get substring from uri starting at location of second slash to the end
set sub_uri [string range [HTTP::uri] $idx end]
just without the overhead of the temporary variable.
It shouldn't be necessary to check the return value of the string first command because it will return -1 if the uri doesn't have a second slash and then the subsequent string range command will return the entire string.
I'll leave it to others to post alternate implementations.
Good luck!
-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