Forum Discussion
Walter_WorkAcct
Altostratus
Apr 24, 2021iRule with multiple 301 redirects only redirecting main URI
I am new to the F5 and working on an irule to 301 permanently redirect traffic from links to our old site to new locations on the new site. The issue is that only the default portion of the code is w...
spalande
Nacreous
Apr 26, 2021is 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
}
}
}Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects
