Forum Discussion
Billy_chuang_16
Jun 25, 2008Historic F5 Account
how do I parse a URI value into a variable
Hi,
I would like to "switch" features base on the URI startwith to switch to a defined procedure.
The probem I head is [HTTP::URI] return the whole URL value which is a...
Robert_Sutcliff
Nimbostratus
Jun 25, 2008Hi,
There are two possible methods, either split the uri to get just the first directory, or use glob pattern matching (this is probably the most extensible)...
switch -glob [string tolower [HTTP::uri] ] {
"/abc*" { pool www }
"/cde*" {
HTTP::header insert Header1 domain2
HTTP::header replace Host www.domain.com
HTTP::uri "/domain2[HTTP::uri]"
pool www
}
default { discard }
}
If you do want to get just the first/base directory name you could use something like [getfield [HTTP::uri] "/" 2] - this would get the second field from the uri, using a field seperator of "/". So you'd get something like "abc" or "cde", you might to add a leading slash (/) back when you want to use it.
It's also possible you would need to do further processing to remove parameters in the uri (eg /abc?var=value, or /abc;jsessionid=x).
Another alternative would be to use the subtr command to retrieve a know number of characters (if your base directories all have just 3 character names) - [substr [HTTP::uri] 0 4]
Rob.
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
