Forum Discussion
iRule to reroute to new site while evaluating variables
- Dec 11, 2020
Hi SteveEason,
string tolower: Returns lowercase value.
when HTTP_REQUEST { if { [string tolower [HTTP::host]] contains "code1"} { HTTP::redirect "https://www.newwebsite.com/Code1&fcRedirect=true" } elseif { [string tolower [HTTP::host]] starts_with "code2"} { HTTP::redirect "https://www.newwebsite.com/Code2&fcRedirect=true" } elseif { [string tolower [HTTP::host]] starts_with "code3"} { HTTP::redirect "https://www.newwebsite.com/Code3&fcRedirect=true" } else { HTTP::redirect "https://www.newwebsite.com[HTTP::uri]&fcRedirect=true" } }
switch version:
when HTTP_REQUEST { switch -glob [string tolower [HTTP::host]] { "*code1*" { HTTP::redirect "https://www.newwebsite.com/Code1&fcRedirect=true" } "*code2*" { HTTP::redirect "https://www.newwebsite.com/Code2&fcRedirect=true" } "*code3*" { HTTP::redirect "https://www.newwebsite.com/Code3&fcRedirect=true" } default { HTTP::redirect "https://www.newwebsite.com[HTTP::uri]&fcRedirect=true" } } }
If codeX tags are contained in uri instead of host, you should use [HTTP::uri] instead of [HTTP::host].
when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "*code1*" { HTTP::redirect "https://www.newwebsite.com/Code1&fcRedirect=true" } "*code2*" { HTTP::redirect "https://www.newwebsite.com/Code2&fcRedirect=true" } "*code3*" { HTTP::redirect "https://www.newwebsite.com/Code3&fcRedirect=true" } default { HTTP::redirect "https://www.newwebsite.com[HTTP::uri]&fcRedirect=true" } } }
Thank you for the clarification. So we were on the right track (at least I want to believe we were).
I've taken your last example and replicated that in our environment and it appears to be doing what we wanted. We will be implementing this in the production environment this afternoon and then we'll know for certain. I appreciate the input. I'll post one more time if everything goes well.
Thanks again!
Recent Discussions
Related Content
* 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