Forum Discussion
Lee_Sutcliffe
Nov 21, 2018Nacreous
Hi Tom,
Your iRule looks ok and would do the job but there's a bit of repetition. I would check the host header first and do it once, then use a switch statement for all your static redirects. As for your 'wildcard' redirect, you can extract the numbers using
getfield
and simply add it as a variable to the end of your redirect.
when HTTP_REQUEST {
set newHost "www.new-example.com"
if {[string tolower [HTTP::host]] eq "www.old-example.com"} {
switch -glob [string tolower [HTTP::uri]] {
"/my-old-path/page-y" {
HTTP::respond 301 Location "https://${newHost}/new-path/page-x"
}
"/my-old-path-2/page-zz" {
HTTP::respond 301 Location "https://${newHost}/new-path-2/page-zzy"
}
"/my-old-path-n/old-page-n" {
HTTP::respond 301 Location "https://${newHost}/new-path-n/new-page-n"
}
"/the/old/slug/*" {
set numbers [getfield [HTTP::uri] / 5]
HTTP::respond 301 Location "https://${newHost}/my/new/url/$numbers"
}
}
}
}
Let me know how you get on.
Lee