I have to do a redirect from default.asp and default.aspx in any path, to just the path (with no filename), with a few exceptions. Initially, I had the following iRule, which worked fine:
when HTTP_REQUEST {
if { [string tolower [HTTP::path]] contains “/accountants” } {
return
}
elseif { [string tolower [HTTP::path]] contains “/businesspartners” } {
return
}
elseif { [string tolower [HTTP::path]] contains “/product/health-insurance” } {
return
}
elseif { [string tolower [HTTP::path]] contains “/default.aspx” } {
set replaceURI [string map [list /default.aspx /] [HTTP::path]]
HTTP::respond 301 Location “$replaceURI”
}
elseif { [string tolower [HTTP::path]] contains “/default.asp” } {
set replaceURI [string map [list /default.asp /] [HTTP::path]]
HTTP::respond 301 Location “$replaceURI”
}
}
However, when time came to add another exception, I decided to rewrite it into a switch statement. I converted the above into:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::path]] {
“/accountants/*” {
return
}
“/businesspartners/*” {
return
}
“/product/health-insurance/*” {
return
}
“/helpkb/*” {
return
}
“*/default.aspx” {
set replaceURI [string map [list /default.aspx /] [HTTP::path]]
HTTP::respond 301 Location “$replaceURI”
}
“*/default.asp” {
set replaceURI [string map [list /default.asp /] [HTTP::path]]
HTTP::respond 301 Location “$replaceURI”
}
}
}
Now, it works halfway. when going to anything/default.asp, I get correctly redirected to /anything/. However, when going to anything/default.aspx, I get redirected to /anything/x, which doesn’t exist. So it appears my last case is taking precedence over the one above it. Anybody know how to clean this up and make it work again, or do I just have to add another elseif to my original rule?