Forum Discussion
Chris_Lappi_164
Jun 14, 2012Nimbostratus
iRule routing to pool with URI trimming
I am trying to direct client requests to a specific pool based on URI information. When the URI contains "/pdf" we would like to send them to pool ABC. This works. What doesnt work is when sending th...
hooleylist
Jun 14, 2012Cirrostratus
Hi Chris,
string trimleft will trim character by character not by the trim string:
http://www.tcl.tk/man/tcl8.4/TclCmd/string.htmM47
string trimleft string ?chars?
Returns a value equal to string except that any leading characters from the set given by chars are removed. If chars is not specified then white space is removed (spaces, tabs, newlines, and carriage returns).
So /pdf/test123 would get rewritten to test123 (without a leading forward slash). This isn't a legal URI so the web app is probably sending back a 400 error for these requests. It would be more precise to use string range to get everything in the URI after the fourth character:
when HTTP_REQUEST {
log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] to [virtual name] [HTTP::host][HTTP::uri]"
if {[string tolower [HTTP::host]] eq "www-qa.digi.com"}{
switch -glob [HTTP::uri] {
"/pdf/*" {
HTTP::uri [string range [HTTP::uri] 4 end /pdf]
log local0. "[IP::client_addr]:[TCP::client_port]: Selected Pool ABC and trimmed /pdf"
pool ABC
}
default {
log local0. "[IP::client_addr]:[TCP::client_port]: Selected Pool:123"
pool PL-123
}
}
}
}
Aaron
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