Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

Simple 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's that are rarely used but need to be redirected to the new websites. The iRule is also checking to see if the request comes in on port 443 and redirects it to port 80. I know that we can probably clean up some of these things and make the rule more efficient. Can someone look at this iRule and see if they know why that I cannot get any redirects to work.

when HTTP_REQUEST {

if {[TCP::server_port] == 443} {
HTTP::redirect "http://[HTTP::host]/[HTTP::uri]"
} else {
if {[HTTP::host] == "www.newlifepubs.com" or [HTTP::host] == "newlifepubs.com"} {
HTTP::redirect "http://www.campuscrusade.com/nlp"
} elseif {[HTTP::host] == "www.mpd.ccci.org" or [HTTP::host] == "mpd.ccci.org"} {
HTTP::redirect "http://staffweb.ccci.org/mpd/index.aspx"
} elseif {[HTTP::host] == "www.staffweb.org" or [HTTP::host] == "staffweb.org" or [HTTP::host] == "staff.ccci.org"} {
HTTP::redirect "http://staffweb.ccci.org"
} elseif {[HTTP::host] == "myspam.ccci.org"} {
HTTP::redirect "https://spam.frontbridge.com"
} elseif {[HTTP::host] == "cars.ccci.org"} {
HTTP::redirect "http://cds.ccci.org/carschoose.asp"
} elseif {[HTTP::host] == "www.movementseverywhere.org" or [HTTP::host] == "movementseverywhere.org"} {
HTTP::redirect "http://www.ccci.org"
} elseif {[HTTP::host] == "www.movementseverywhere.net" or [HTTP::host] == "movementseverywhere.net"} {
HTTP::redirect "http://www.ccci.org"
} elseif {[HTTP::host] == "www.movementseverywhere.com" or [HTTP::host] == "movementseverywhere.com"} {
HTTP::redirect "http://www.ccci.org"
} else {
discard
}
}

}
0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Hi,

maybe you should try TCP::local_port instead of TCP::server_port.

On the first request you don't know at this point which server will be elected and therefore don't know already the port. With this TCP::local_port you'll check on which port the client established its connection on the bigip

If it doesn't work, can you add some logging to your iRule like

log local0. " uri is [HTTP::uri]"

and some log for each statement, then give us the output of /var/log/ltm it will help understand what is happening

thanks
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Thanks, I removed the https redirect to http and we still cannot get the url's to redirect to the new url's in the rule.
Is it possible to do a HTTP url redirect to a different url with matched conditions.
Here is the new iRule:

when HTTP_REQUEST {
switch -glob [HTTP::host] {
{"*newlifepubs.com"} {
HTTP::redirect "http://www.campuscrusade.com/nlp"}
{"*mpd.ccci.org"} {
HTTP::redirect "http://staffweb.ccci.org/mpd/index.aspx"}
{"*staffweb.org"} {
HTTP::redirect "http://staffweb.ccci.org"}
{"staff.ccci.org"} {
HTTP::redirect "http://staffweb.ccci.org"}
{"myspam.ccci.org"} {
HTTP::redirect "https://spam.frontbridge.com"}
{"cars.ccci.org"} {
HTTP::redirect "http://cds.ccci.org/carschoose.asp"}
{"*movementseverywhere.org"} {
HTTP::redirect "http://www.ccci.org"}
{"*movementseverywhere.net"} {
HTTP::redirect "http://www.ccci.org"}
{"*movementseverywhere.com"} {
HTTP::redirect "http://www.ccci.org"}
default {
discard
}
}
}
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
I forgot to add that there is no Pool assigned to the Virtual Server that these old URL's are in. All of the URL's are hosted at different locations throughtout the world. We are just trying to redirect traffic from an old URL to a new URL.


0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER
Do 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
0