Forum Discussion
Persistance iRule
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
7 Replies
- The_Bhattman
Nimbostratus
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 followingwhen 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, TJwhen 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" } } } } - The_Bhattman
Nimbostratus
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 stringsFor examplethe following URL:1 http://www.example.com:8080/main/in...ogin=checkThe path is:1 /main/index.jspNote 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=checkthe path is:1 /main/index.jsp;session_id=abcdefghAs 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
- Kevin_Davies_40
Nacreous
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 WebUIWorking 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- The_Bhattman
Nimbostratus
Hi TJ,
Glad it worked out
Bhattman
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com