Forum Discussion
Looking to separate out URL from URI
Nailed it finally....
HTTP::path -- that just returns the path without the query string
HTTP::uri -- returns the path + the query string
I actually wanted to just use HTTP::path afterall. here's how I did it...
when HTTP_REQUEST {
set host [HTTP::host]
set uri_list [split [string tolower [HTTP::path]] /]
if { [lindex $uri_list 2] equals "admin"} {
HTTP::respond 302 Location "https://$host/user"
}
}
Basically it just redirect the client to the "/user" directory if they try and access the "/admin" directory. The real key item here is the use of TCL lists and "split". I got in this mentality while working with python and using their lists frequently to solve problems like this.
"lindex" just returns the item at that index location and acts the exact same way as you'd expect "list[2]" to work in C or C++
This is also another valuable little snippet so that you can get the size of the list (all the different locations in the path + the filename) and then dump the actual filename in the path.
set list_size [llength [split [HTTP::uri] /]]
if{ $list_size > 1 } {
log local0. "Last item in the list: [lindex $uri_list [expr $list_size -1]]"
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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
