Forum Discussion
david_quint_204
Nimbostratus
Sep 25, 2008Simple HTTP redirects not working
Guys, I am having some issues with migrating an old iRule from v4.x to v9.45. We have an External IP address 65.170.177.8 (NAT'ed to an internal address ie:VIP) that has DNS entries for multiple URL'...
hoolio
Cirrostratus
Sep 26, 2008Do all of the domains you're redirecting to resolve to the VIP which this rule is running on? From your last post, it sounds like they don't. But if they do, you'll get constant redirect loops unless you check the host and the URI. Perhaps you want to add a check to see if the URI is not / and then redirect for the switch cases where you're redirecting to /.
Below is a correctly formatted switch example. For details on switch, you can check the DC wiki page (Click here) or the TCL man page (Click here). I added log statements to the first couple of switch cases. If the rule doesn't work as you expect, you can add logging to each case to see what's being triggered.
when HTTP_REQUEST {
log local0. "[IP::client_addr]:[TCP::client_port]: New HTTP request to [HTTP::host][HTTP::uri]"
switch -glob [string tolower [HTTP::host]] {
"*newlifepubs.com" {
log local0. "[IP::client_addr]:[TCP::client_port]: Matched 1"
HTTP::redirect "http://www.example.com/nlp"
}
"*mpd.example.org" {
log local0. "[IP::client_addr]:[TCP::client_port]: Matched 2"
HTTP::redirect "http://staffweb.example.org/mpd/index.aspx"
}
"*staffweb.org" {
log local0. "[IP::client_addr]:[TCP::client_port]: Matched 3"
HTTP::redirect "http://staffweb.example.org/"
}
"staff.example.org" {
HTTP::redirect "http://staffweb.example.org/"
}
"myspam.example.org" {
HTTP::redirect "https://spam.example.com/"
}
"cars.example.org" {
HTTP::redirect "http://cds.example.org/carschoose.asp"
}
"*movementseverywhere.example.org" -
"*movementseverywhere.example.net" -
"*movementseverywhere.example.com" {
HTTP::redirect "http://www.example.org/"
}
default {
log local0. "[IP::client_addr]:[TCP::client_port]: No match"
discard
}
}
}
Aaron
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
