Forum Discussion

TJ_Vreugdenhil's avatar
Aug 17, 2011

Persistance iRule

VIP = 10.7.200.21

 

URL = http://alerts.company.edu/

 

 

URI needs to have persistence = http://alerts.company.edu/client/*

 

URI no persistence = http://alerts.company.edu/csi/*

 

 

 

when HTTP_REQUEST {

 

switch -glob [HTTP::uri] {

 

"/client/* {

 

persist sticky 600

 

use pool athoc_pool_1

 

default {

 

HTTP::redirect http://alerts.company.edu/csi

 

}}}

 

 

 

When I apply the iRule above, the other URI stops working. Is there something I can change? Do I need to use 'persist cookie' instead of 'persist sticky'?

 

 

Thank you!

 

 

-TJ

 

  • Hi TJ,

    The URI stopping is something that doesn't necessarily mean you are applying persistance. However, another approach is that you can setup cookie persistance in the profile. Then you can rewrite the irule to the following

    
    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::uri]] {
          "/client/*" { pool athoc_pool_1 } 
          default {
             persist none
             HTTP::redirect "http://[HTTP::host]/csi"
             }
        }
    }
    

    I hope this helps

    Bhattman

  • I used the default cookie persistence profile (insert mode) and applied the iRule you suggested. I believe persistence is working correctly, but the website reports a redirect loop:

    If I update the iRule to use HTTP:path and remove the trailing '/' - Will that prevent it from looping, or do I have to use an " & amp & " operators with a string? Any helpful debug log statements are appreciated. Still learning 🙂

    when HTTP_REQUEST { 
    log local0.debug "using persistence" 
    switch -glob [string tolower [HTTP::path]] { 
    "/client" { pool athoc_pool_1 }
    default { 
    persist none 
    HTTP::redirect "http://[HTTP::host]/csi"
    log local0.debug "using redirect" 
    } 
    } 
    }

    -TJ

  • I am thinking the logic would be something like the following, but need help with syntax.

    Thanks,

    TJ

    
    when HTTP_REQUEST { 
    log local0.debug "using persistence" 
    if {([class match [switch -glob [string tolower [HTTP::path]] { 
    "/client"}}] { pool athoc_pool_1
    && !([string tolower [HTTP::path]] starts_with "/client")} {
    default { 
    persist none 
    HTTP::redirect "http://[HTTP::host]/csi"
    log local0.debug "using redirect" 
    } 
    } 
    }
    }

  • Posted By work_hard_play_hard on 08/17/2011 12:12 PM

    I used the default cookie persistence profile (insert mode) and applied the iRule you suggested. I believe persistence is working correctly, but the website reports a redirect loop:

    If I update the iRule to use HTTP:path and remove the trailing '/' - Will that prevent it from looping, or do I have to use an " & amp & " operators with a string? Any helpful debug log statements are appreciated. Still learning 🙂

    when HTTP_REQUEST { 
    log local0.debug "using persistence" 
    switch -glob [string tolower [HTTP::path]] { 
    "/client" { pool athoc_pool_1 }
    default { 
    persist none 
    HTTP::redirect "http://[HTTP::host]/csi"
    log local0.debug "using redirect" 
    } 
    } 
    }

    -TJ

    If you remove the "/" in the manner you suggested the iRULE condition statement will match exactly http://alerts.company.edu/client and then send it over to the alternative pool. It will do a redirect if it's "http://alerts.company.edu/client/something" or "http://alerts.company.edu/client/something/something" , etc. If you use HTTP::path you are basically only seeing the path and not any query strings For example the following URL:

     

     

    1 http://www.example.com:8080/main/in...ogin=check

     

     

     

     

     

    The path is:

     

     

    1 /main/index.jsp

     

     

     

     

     

    Note that only ? is used as the separator for the query string. So, for the following URL:

     

     

    1 http://www.example.com:8080/main/in...ogin=check

     

     

     

     

     

    the path is:

     

     

    1 /main/index.jsp;session_id=abcdefgh

     

     

     

     

    As you can see HTTP::path doesn't contain query string which is not the entire URL.

    So if you are okay with that you can proceed to use it. However, i would further investigate whether the loop is explicitly being caused by the webserver or the iRULE itself.

    I hope this helps

    Bhattman

  • Errr...

    when HTTP_REQUEST {

    log local0.debug "using persistence"

    switch -glob [string tolower [HTTP::path]] {

    "/client" { pool athoc_pool_1 }

    default {

    persist none

    HTTP::redirect "http://[HTTP::host]/csi"

    log local0.debug "using redirect"

    }

    }

    /client needs to have a * after it otherwise it will match anywhere in the string. "/client*"

    You redirect to the same VIP with /csi so this will fall though to the redirect again hence the infinite loop.

    If you really want everything that does not match /client* to be redirected to /csi then this should do it.

    when HTTP_REQUEST {

    log local0.debug "using persistence"

    switch -glob [string tolower [HTTP::path]] {

    "/client*" { pool athoc_pool_1 }

    "/csi*" { persist none }

    default {

    HTTP::redirect "http://[HTTP::host]/csi"

    log local0.debug "using redirect"

    }

    }

    Kevin (Jarvil)

  • I couldn't get the persistence profile to take in the WebUI when I had the iRule in place, so I had to manually set it in the iRule and remove the persistence profile in the WebUI

     

     

    Working iRule:

     

     

    when HTTP_REQUEST {
    log local0.debug "using persistence" 
    switch -glob [string tolower [HTTP::path]] { 
    "/client*" { persist dest_addr 600 }
    default { 
    HTTP::redirect "http://[HTTP::host]/csi"
    log local0.debug "using redirect" 
    }
    }
    }

     

     

    Thanks to both of you for your help. I appreciate it!

     

     

    -TJ