Forum Discussion
TCL errors
Ah, so you are performing that match on purpose. Got it. You can either use the catch method already articulated, or:
set cn "VURL_[string tolower [HTTP::host]]"
if { [class exists "$cn"] } {
set redirect_url [class lookup [HTTP::path] $cn]
... etc ...
}
The problem with using catch is, it will catch any runtime error, not just this one, so you could end up masking a different issue, which you would actually want to log.
Incidentally, the quoting I use above (in the set ... command and the class exists ... command) is intentional. If a space creeps in anywhere, it'll cause a runtime exception. Since class names cannot have spaces, and you validated the existence in the class exists ..., quoting isn't needed in the class lookup ....
Also, ordinarily we recommend against variable assignment for command retrieved values (e.g., it's not usually necessary to assign [HTTP::path] to a variable, even if it's referenced more than once because it is generally cheaper to get the value from the command each time than to expand a Tcl variable). In this case, however, we want to avoid duplicate execution of string tolower ...; hence the assignment.
Much appreciated Vernon. I will try following
set cn "VURL_[string tolower [HTTP::host]]"
if { [class exists "$cn"] } {
set redirect_url [class lookup [HTTP::path] $cn]
HTTP::redirect $redirect_url
log local0. "Redirecting: [HTTP::host][string tolower [HTTP::uri]] to $redirect_url "
}
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
