Forum Discussion
wlepkin_98758
Jan 30, 2012Nimbostratus
string trimleft, and assigning HTTP::uri
Hi --
I'm trying to use the 'string trimleft' function to change the URI, and must be doing something wrong. Here's what I've got, with lots of log statements so I can see what's going on:
when HTTP_REQUEST {
set loweruri [string tolower [HTTP::uri]]
log local0. "String-to-lower URI is $loweruri"
if { $loweruri starts_with "/chart" } then
{
log local0. "Original URI is [HTTP::uri]"
log local0. "string trimleft = [string trimleft [HTTP::uri] /chart]"
HTTP::uri [string trimleft [HTTP::uri] /chart]
log local0. "New URI is [HTTP::uri]"
log local0. "Redirecting to http://ifp-vip:8080[HTTP::uri]"
HTTP::redirect ]
unset loweruri
}
}
The point being that if the URI starts with '/chart' then you want to strip that off, and send what's left to a different host:port.
If I send request: http://denfpot-vip/chart/abc
This is what shows up in the log:
: String-to-lower URI is /chart/abc
: Original URI is /chart/abc
: string trimleft = bc
: New URI is /chart/abc
: Redirecting to http://ifp-vip:8080/chart/abc
So, this prompts two question:
- why is trimleft returning 'bc' instead of '/abc'?
- why is the URI not getting reassigned (even to the wrong thing)?
Software version is 9.3.1, perhaps that's relevant.
As always, thanks much for your help.
WDL
- hoolioCirrostratusstring trimleft operates by removing characters not words. So a is part of the characters you have in your "trim" list so it's removed from the source string. If you want to chop off /chart, you could use string range or scan:
when HTTP_REQUEST { if {[string tolower [HTTP::uri]] starts_with "/charts"}{ HTTP::redirect "http://ifp-vip:8080[string range [HTTP::uri] 7 end]" log local0. "redirecting to http://ifp-vip:8080[string range [HTTP::uri] 7 end]" } }
- wlepkin_98758NimbostratusHoolio/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