Forum Discussion
mike_gatti_6169
Nimbostratus
May 17, 2007Using array/class to define veriable and use for redirect
I have been trying to use an array or class to define a variable that will be used for a redirect. The iRule that I have created (and not working) is:
when RULE_INIT {
array set sites...
May 17, 2007
A couple of common mistakes.
1. in your first if statement, you are comparing a string "[HTTP::uri]" with an array "sites". If you want to compare for a string's existence within a list of items, you'll have to use our "matchclass" command. Also, if you are hand-rolling the list, it needs to be a TCL list, not an array.
when RULE_INIT {
set sites [list \
"/site1" \
"/site2" \
]
}
when HTTP_REQUEST {
if { [matchclass [HTTP::uri] starts_with $::sites] } {
HTTP::redirect "http://www.domain.com/global/[string range [HTTP::uri] 1 end]"
} elseif { [HTTP::uri starts_with "/global" } {
pool site_pool
}
}
2. In your second code sample you are defining the class in the iRule. The "class ..." code that is often posted to these forums is the internal format of the data group (or class) from within the internal configuration. You'll need to define this as a data group within the iRules section of the GUI.
Now, after all that is said, for small lists of items, it is much more optimal to use a switch statement like this:
when HTTP_REQUEST {
switch -glob [HTTP::uri] {
"/site1*" -
"/site2*" {
HTTP::redirect "http://www.domain.com/global/[string range [HTTP::uri] 1 end]"
}
"/global*" {
pool site_pool
}
}
}
-Joe
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
