Forum Discussion
SanjayP
Apr 26, 2021Nacreous
is your old site VIP only being used for HOST "oldsite.ournewsite.net"? In other words, Is there any other FQDN that also maps/shares same VIP address and shouldn't be redirected to the new site?
If this is standalone VIP for host oldsite.ournewsite.net, then you can use switch statement for URI and no need to specifically check for old site Host. iRule would be below
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/foo*"
{
HTTP::respond 301 "Location" "https://ournewsite.net/oldsitestuff/foo"
}
"/bar*"
{
HTTP::respond 301 "Location" "https://ournewsite.net/oldsitestuff/bar"
} default {
HTTP::respond 301 "Location" "https://ournewsite.net/oldsitestuff"
}
}
}
In case, your old site VIP also host some other hosts/fqdn behind it, then you can use something like below
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::host]] {
"oldsite.ournewsite.net" {
if { [string tolower [HTTP::uri]] starts_with "/foo" } {
HTTP::respond 301 "Location" "https://ournewsite.net/oldsitestuff/foo"
} elseif { [string tolower [HTTP::uri]] starts_with "/bar" } {
HTTP::respond 301 "Location" "https://ournewsite.net/oldsitestuff/bar"
else {
HTTP::respond 301 "Location" "https://ournewsite.net/oldsitestuff"
}
}
} default {
return
}
}
}