Forum Discussion

Jean_Mamène's avatar
Dec 05, 2022

Irule based on source IP and URI request


I want to redirect on pool the request if the IP source and URI request match to the condition.

On version BIG-IP 11.5.4 I think it's better to do with iRule.


7 Replies

  • Hi Jean, 

    A redirect is always URL related, and a forward is pool related. You somehow mixed redirect and pool in your question which makes no sense for me.

    Could you clarify you current setup slightly more in detail?

    You have a VS which is serving content from lets say Pool_A? Now you want to forward requests to Pool_B, if known Client IPs requesting a specific /path? Or do you want to HTTP redirect the requests to an external site (e.g. https://sitename/ ), if known Clients requesting a specific /path?

    Cheers, Kai


    • Jean_Mamène's avatar
      Icon for Cirrus rankCirrus

      Actually I have iRule1
      I need iRule2. two source IP different but same request URI, and if source IP is I need to go on pool1 and pool2 if

      • Kai_Wilke's avatar
        Icon for MVP rankMVP

        HI Jean,

        Ideally you could integrate the Source IP Condition to your existing iRule. If you attach a second iRule to your setup without knowing what the first iRule does, it may have some side effects. But lets give it a try with a carefully choosen syntax...



        when HTTP_REQUEST priority 750 {
        	# Check if iRule 1 has already responded the request...
        	if { [HTTP::has_responded] == 1 } then {
        		# iRule 1 has already HTTP::responded the request. We abort iRule execution...
        	} elseif { not [string tolower [HTTP::path]] starts_with "/uri1/test" } then {
        		# HTTP request is for a different path. We should not care...
        	} elseif {  [IP::client_addr] equals "" } then {
        		# Client is sending requests to /uri1/test. We forward to pool1
        		pool pool1
        	} elseif { [IP::client_addr] equals "" } then {
        		# Client is sending requests to /uri1/test. We forward to pool2
        		pool pool2
        	} else {
        		# We dont care for remaining clients...


        The provided iRule uses "priority 750" and should therefor most likely execute after your first iRule (default priority is 500 unless specified otherwise) finished. The provided iRule checks at first if your first iRule has already HTTP::responded the incomming request and aborts further processing if this is true. It will then filter out every HTTP::path not starting_with /uri1/test and abort further processing. Requests starting_with /uri1/test will be further analysed, to see if the client is or and request from those clients will be then forwarded either to pool1 or pool2. The iRule does nothing for remaining client IPs...

        HTH and Cheers, Kai

  • You might be able to do something similar to the following. If it ends up being a long list I would recommend using a data group and using that to limit your lines of code because iRules do have a line limit.

        set DEFAULT_POOL [LB::server pool]
    when HTTP_REQUEST {
        set URI [string tolower [HTTP::uri]]
        if { [IP::addr [IP::client_addr] eq] } {
            if { $URI eq "/my/uri/path" } {
                pool my_pool_for_this_uri
            } elseif { $URI eq "/my/other/uri/path" }
                pool my_pool_for_other_uri
            else {
        } else {