Forum Discussion
Redirect both host and path via iRules
Hi Daniel,
the
[switch] "default" or [if] "else" conditions are both optional. You can either leave them empty, but you can also remove the default/else conditions if you like. The outcome would be exactly the same. But I personaly tend to keep those condition for better visibility and add a meaningful comment to it...
when HTTP_REQUEST {
switch -exact -- [string tolower [HTTP::host]] {
"abc.com" -
"www.abc.com" {
HTTP::redirect http://abc.123.com
}
"def.com" -
"www.def.com" {
switch -exact -- [string tolower [HTTP::uri]] {
"/example" {
HTTP::redirect "/site1/example"
}
"/example2" {
HTTP::redirect "/site2/example"
}
default {
Forward to default pool
}
}
}
default {
reject
}
}
}
Note: You should use
only if you need to match certain single charcter wildcard -glob
or general wildcards ?
. If matching conditions without wildcards, then *
would be the better choice in terms of performance.-exact
Note: If you need different rulesets for HTTP and HTTPS access, then it would be more effective to have two independent iRules. Well, if the differences are not that much, then you could also include contitions to make decission based on the accessed protocol, but its those conditions add a slightly overhead to your CPU. But on the otherhand may be reduce the administrative overhead to maintain the two almost identical iRules.
Note: Your Datagroup approach should be fine. Datagroups are easier to manage for iRule startes, since they don't require you to have a deep iRule knowledge for daily changes.
Note: When testing/changing iRules, then always keep in mind, that iRules changes are only become effective for new TCP connections. I guess the trouble of your "default" condition experiments may be the result of keep- alive TCP connections?
Cheers, Kai
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
