That rule should work fine. I suggest adding logging. In addition, is there more to the iRule? If not, I recommend strongly against setting
$URI
. In fact, it's sub-optimal to set
$HOST
as a variable, unless it is going to be used more than once. Normally, in programming, coding defensively and optimizing for readability and maintenance efficiency is sensible, but that's not the case with iRules. If one must choose between those things and performance, you almost always want to choose performance, since it executes with each connection (or, in the case of the rule below, each HTTP Request received). Finally, the use of
-glob
on the
switch
should be used only if you intend to perform glob matching. For strict matching, it's about 10% faster to exclude the
-glob
. Perhaps give this a try:
when HTTP_REQUEST {
switch [string tolower [HTTP::host]] {
"my.com" -
"www.my.com" {
log local0. "Matched HTTP::host = [HTTP::host]"
HTTP::respond 301 Location "http://www.my.com"
}
}
Look in
/var/log/ltm
for the log message. If it does not match when you are going to
https://my.com, then try the following:
when HTTP_REQUEST {
log local0. "Host header = [string tolower [HTTP::host]]"
switch [string tolower [HTTP::host]] {
"my.com" -
"www.my.com" {
HTTP::respond 301 Location "http://www.my.com"
}
}
and try the request, again looking in
/var/log/ltm
(be aware that, if the request rate is quite high, the log may be suppressed, and you may end up with a lot of logging!). Once you are done testing, don't forget to remove the logging statements, of course.