Forum Discussion
Irule
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"" -
"/" {
HTTP::redirect "https://cache-monitor-AMG.com/home"
}
}
}
The switch matches cases against the expression. The string tolower normalizes the case of the Request-URI [1] to facilitate reliable comparison regardless of provided case [2]. The -glob allows for glob-style matching. [3] As you observe, the first case match is the empty string. The dash following it means that this case "falls through". That is, if the case matches, it will perform whatever action is specified for the case that follows it (unless that case is also a fall through, in which case it keeps falling through until it finds a case with an associated code branch).
So, in this case, the outcome is the same regardless whether HTTP::uri is empty or a slash ("/"). The HTTP::redirect is an explicit redirect, which means a 302 status code is returned to the client, along with a Location header containing the new URL.
[1] people sometimes confuse HTTP::uri with HTTP::path. The latter is probably what is intended in this case, since it is the path part of the Request-URI. The former would also include things like query parameters.
[2] for the Request-URI, this is usually unnecessary, violates the HTTP RFC, and for these match cases costs execution cycles without adding value.
[3] in this case, glob-matching is not needed and possibly costs cycles without adding value.
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