Redirect some users if they hit a certain uri

Hi,

I need to redirect certain users (client IP’s) when they land to a certain page behind my virtual page.

Basically the below and also checking if the uri equals a page:

when HTTP_REQUEST {
    if { [class match [IP::client_addr] equals my_ip_dg] } {
        HTTP::redirect "http://10.200.200.200"
    }
}

However, my efforts have been in vain. What would I need to do to get this work?

You would have to explain what went wrong with your efforts to better assist you. I think this iRule should work:

when HTTP_REQUEST {
    if { ([class match [IP::client_addr] eq my_ip_dg]) and ([HTTP::uri] eq "/abcd") } {
        HTTP::redirect "http://10.200.200.200/"
    }
}

You can also use client accepted condition.

Hi Gurdip,

unless you’re using HTTP/1.0 without keep-alive sessions, then it would be more effective to evaluate the Client IP during the CLIENT_ACCEPTED event (triggered once at the beginning of each TCP session), store the

[class match]

results into a

$variable

and the use the stored results on each single HTTP_REQUEST.

when CLIENT_ACCEPTED {
    if { [class match [IP::client_addr] equals my_ip_dg] } {
        set is_redirect 1
    } else {
        set is_redirect 0
    }
}
when HTTP_REQUEST {
    if { $is_redirect } then {
        if { [string tolower [HTTP::path]] equals "/somepath" } then {
            HTTP::redirect "http://10.200.200.200"
        }
    }
}

Note: Feel free to combinate theandconditions. I’ve splitted them just for demonstration purposes.

if $is_redirect
if HTTP::path

Cheers, Kai