Forum Discussion
Deb_Allen_18
May 09, 2006Historic F5 Account
calling a command from a class
I'm building lots of variations on a theme for redirects, and would like to be able to use dynamic request variables to build redirect responses.
I was hoping to use command strings stored in a class to build the redirect location dynamically, to avoid coding a separate condition/action for each location pattern:
class HostRedirects {
www.domain.com 301 https://www.domain.com[HTTP::uri]
host.domain.com 302 http://host2.domain.com/index.html
another.domain.com 301 https://www.domain.com/another[HTTP::uri]
...
}
rule HostRedirects {
when HTTP_REQUEST {
set row [findclass [getfield [HTTP::host] ":" 1] $::HostRedirects]
if { not ($row eq "")}{
HTTP::respond [getfield $row " " 2] Location [getfield $row " " 3]
unset row
return
}
}
}
but I can't seem to get the [HTTP::uri] command that is part of the class member to evaluate, so the redirect location comes back literally as "https://www.domain.com[HTTP::uri]", rather than "https://www.domain.com/my/favorite/website.html"
Any ideas?
/deb
- Deb_Allen_18Historic F5 Account(oops, had to clean that up a little.
- Colin_Walker_12Historic F5 AccountTry adding an eval line in your rule.
rule HostRedirects { when HTTP_REQUEST { set row [findclass [getfield [HTTP::host] ":" 1] $::HostRedirects] if { not ($row eq "")}{ set tmpRow [eval $row] HTTP::respond [getfield $tmpRow " " 2] Location [getfield $tmpRow " " 3] unset row unset tmpRow return } } }
- Deb_Allen_18Historic F5 Accountgetfield commands are definitely returning what's expected, problem is just that it's not being interpreted.
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