Michael_193050
Jul 16, 2015Nimbostratus
redirect based on host and uri
Hi i have the below irule which is working fine. I'm trying to make it more efficient and only issue one redirect if the request came in as https://oldsite.com/. Currently what happens is i get the first redirect, then the second one when the uri matches /.
The existing irule:
when HTTP_REQUEST {
if {[string tolower [HTTP::host]] eq "oldsite.com"} {
HTTP::redirect "https://newsite.com[HTTP::uri]"
}
elseif {[string tolower [HTTP::uri]] eq "/"} {
HTTP::redirect "https://newsite.com/identitymanagement/default.aspx"
}
}
The new iRule I'm attempting to get working is:
when HTTP_REQUEST {
if { ([string tolower [HTTP::host]] eq "oldsite.com") and ([string tolower [HTTP::uri]] eq "/") } {
HTTP::redirect "https://newsite.com/identitymanagement/default.aspx"
}
elseif {[string tolower [HTTP::uri]] eq "/"} {
HTTP::redirect "https://newsite.com/identitymanagement/default.aspx"
}
}
This fixes the multiple redirects.
The problem i'm having is if i get a request for https://oldsite.com/path1, i still need to redirect to the https://newsite.com/path1. I can't figure out how to also take into account this. I've also tried converting this to a switch statement, but wasn't able to find a way to check both http::host and http::uri to formulate the correct redirect.
Thanks,