HTTP Redirection iRules
Hi,
A customer wanted a new web solution and chose Big-IP 3900 to use as a load balancer. They want to migrate from the existing environment to the new one with as little downtime / 404 errors as possible by redirecting old links to the corresponding site in the new environment.
This has led me to create a ton of redirection rules. I am pretty new to Big-IP, so I would like to know what the best practices are around handelig a lot of URIs. This is how I solved it:
when HTTP_REQUEST {
if { ([string tolower [HTTP::host]] contains "example.com") and [HTTP::uri] contains "/thisisanoldsite" } {
HTTP::redirect "https://www.example.com/this/is/the/equivilant/site"
}
if { ([string tolower [HTTP::host]] contains "example.com") and [HTTP::uri] contains "/hey/whatsup.aspx" } {
HTTP::redirect "https://www.example.com/abc/def/example.aspx"
}
if { ([string tolower [HTTP::host]] contains "example.com") and [HTTP::uri] contains "/page206.aspx" } {
HTTP::redirect "https://www.example.com/subsite/URI/page.aspx"
}
if { ([string tolower [HTTP::host]] contains "example.com") and [HTTP::uri] contains "/AboutThisPage" } {
HTTP::redirect "https://www.example.com/About/Page.aspx"
}
...
}
}
This rule is applied on the HTTP Virtual Server. As you can see, everything is redirected to https://, so this iRule will only be applicable on the users first request.
This is just a small part of it. The complete rule contains about 1200 URIs, devided in two seperate iRules.
Can this be changed into something a little less complex? Using switch insted of if's? I would also like if these rules replied with a HTTP 301 Permanently moved status code. Should I replace every HTTP::redirect with HTTP::respond 301 location ?
In advance, thank you.
Regards,
Martin