Forum Discussion

DushyantSingh_1's avatar
DushyantSingh_1
Icon for Nimbostratus rankNimbostratus
Jul 20, 2015

URL redirection based on IP and Port information

Hello,

 

I need to deliver an irule to my client with a condition that traffic will hit on configured VIP 172.x.x.x:80 from two source 160.12.x.x or 90.1.x.x on port 5050 which needs to be routed to different URL xyz.com or abc.com.

 

Client_Accept doesn't work with redirect to. Please help.

 

2 Replies

  • I'm assuming you're talking about source addresses in the 160.12.0.0 and 90.1.0.0 ranges. Is 5050 a source port? Otherwise:

    when HTTP_REQUEST {
        if { [IP::addr [IP::client_addr] equals 160.12.0.0/16] } {
            HTTP::redirect "http://abc.com"
        } elseif { [IP::addr [IP::client_addr] equals 90.1.0.0/16] } {
            HTTP::redirect "http://xyz.com"
        }
    }
    

    https://devcentral.f5.com/wiki/iRules.IP__addr.ashx

  • Okay, so:

    when HTTP_REQUEST {
        if { ( [IP::addr [IP::client_addr] equals 160.12.0.0/16] ) and ( [TCP::client_port] == "5050" ) } {
            HTTP::redirect "http://abc.com"
        } elseif { ( [IP::addr [IP::client_addr] equals 90.1.0.0/16] ) and ( [TCP::client_port] == "5050" ) } {
            HTTP::redirect "http://xyz.com"
        }
    }
    

    Or

    when HTTP_REQUEST {
        if { [TCP::client_port] == "5050" } {
            if { [IP::addr [IP::client_addr] equals 160.12.0.0/16] } {
                HTTP::redirect "http://abc.com"
            } elseif { [IP::addr [IP::client_addr] equals 90.1.0.0/16] } {
                HTTP::redirect "http://xyz.com"
            }
        }
    }