Forum Discussion
norrtom_376408
Nimbostratus
Nov 21, 2018Can someone help me with iRule redirects?
Hi All!
I am new to F5 and iRules. I'm helping out a client of mine to do redirections.
I understand that if I want to redirect several URL's from an old domain to a new one, i will do as this:
...
Lee_Sutcliffe
Nacreous
Nov 21, 2018Hi 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
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
