Forum Discussion

saidshow_251381's avatar
saidshow_251381
Icon for Cirrostratus rankCirrostratus
Jun 25, 2018

iRule to run only once - implementing persistence

Hi All,

 

I have a simple iRule that I want to run only once per user. The intention is to check the IP of the client and redirect based on the identified continent. Catering for false positives, users that are redirected, will have the option to move back to the original site. In this case we cannot have the iRule run a second time or they will be directed back to the previous site once more and then be stuck in a loop.

 

I have been looking at Hash Persistence on the LTM. I'll investigate further to see if this can perform the task I require.

 

Thanks in advance.

 

    when HTTP_REQUEST {

    if { ([ whereis [IP::client_addr] country] eq EU ]) } {
         HTTP::redirect "https://I-See-You-Are-In-Europe"
    }

    For verification, tail /var/log/ltm as you implement the changes
    log local0. "IP: [IP::client_addr]; Continent Code: [whereis [IP::client_addr] country]]"

}

1 Reply

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    You can use

    HTTP::response
    to do the HTTP redirect, and set a temporary HTTP cookie in the same operation. If the user comes back again (with the cookie), you can tell the irule not to do the redirect.