Forum Discussion
Having issue with multiple if statements for irule
What I am trying to do is have / and specific data group list URIs going to pool B and the rest of the traffic going to pool A. Issue is that when a URI contains part of an entry in the data group list it uses that pool (example /test is in the dgl and if /test/documents is requested it goes to the dgl not pool A). So I tried the following irule but it is not working.
when HTTP_REQUEST { if { ( [HTTP::uri] equals "/A/documents" ) or ( [HTTP::uri] equals "/B/documents" ) or ( [HTTP::uri] equals "/A/document-library" ) or ( [HTTP::uri] equals "/B/document-library" ) or ( [HTTP::uri] equals "/A/video" )} { pool pool_default.domain.com } if { ( [HTTP::uri] equals "/" ) or ( [class match [string tolower [HTTP::uri]] starts_with dgl_aem.domain.com] ) } { pool pool_alternate.domain.com } else { pool pool_default.domain.com } }
17 Replies
- kunjan
Nimbostratus
Isn't it working as expected?
class match[string tolower[HTTP::uri]]starts_with dgl_aem.domain.com]
which is
class match "/test/documents" starts_with "/test"Should use "equals" instead, for your logic to work ?
- JeffM
Nimbostratus
What I am looking for is an irule that can route: if /A/docs, /B/docs, or /C/docs use pool1. Then, if not those URIs but is / or contained in the data group list (dgl_aem.domain.com) use pool2. else use pool1. So, if the URI /A/testsite is used and /A is definded in the data group list it will use the pool2, but if /A/docs is used it will goto pool1. Right now with my iRule /A/testsite and /A/docs all goto pool2
- kunjan_118660
Cumulonimbus
Isn't it working as expected?
class match[string tolower[HTTP::uri]]starts_with dgl_aem.domain.com]
which is
class match "/test/documents" starts_with "/test"Should use "equals" instead, for your logic to work ?
- JeffM
Nimbostratus
What I am looking for is an irule that can route: if /A/docs, /B/docs, or /C/docs use pool1. Then, if not those URIs but is / or contained in the data group list (dgl_aem.domain.com) use pool2. else use pool1. So, if the URI /A/testsite is used and /A is definded in the data group list it will use the pool2, but if /A/docs is used it will goto pool1. Right now with my iRule /A/testsite and /A/docs all goto pool2
- kunjan
Nimbostratus
Try with
[class match [string tolower [HTTP::uri]] contains dgl_aem.domain.com]
- JeffM
Nimbostratus
If I enter http://www.domain.com/A/docs/legal-notices I still goto pool_default_domain.com vs. pool_alternate.com. I need if the top IF statements match to exit the irule and use the defined pool. It seems like the irule is reading the last success not the first.
- kunjan_118660
Cumulonimbus
Try with
[class match [string tolower [HTTP::uri]] contains dgl_aem.domain.com]
- JeffM
Nimbostratus
If I enter http://www.domain.com/A/docs/legal-notices I still goto pool_default_domain.com vs. pool_alternate.com. I need if the top IF statements match to exit the irule and use the defined pool. It seems like the irule is reading the last success not the first.
- JeffM
Nimbostratus
My irule did not dsiplay very well - reposting so it is easier to read. when HTTP_REQUEST { if { ( [HTTP::uri] equals "/A/documents" ) or ( [HTTP::uri] equals "/B/documents" ) or ( [HTTP::uri] equals "/C/documents" ) or ( [HTTP::uri] equals "/D/documents" ) or ( [HTTP::uri] equals "/E/documents" )} { pool pool_default_domain.com } if { ( [HTTP::uri] equals "/" ) or ( [class match [string tolower [HTTP::uri]] starts_with dgl_aem.domain.com] ) } { pool pool_alternate.com } else { pool pool_default.domain.com } - kunjan
Nimbostratus
I need if the top IF statements match to exit the irule and use the defined pool.
Are your referring to this:
if { ( [HTTP::uri] equals "/" ) or ( [class match [string tolower [HTTP::uri]] starts_with dgl_aem.domain.com] ) } {
What is the string list in dgl_aem.domain.com expected to match here?
- JeffM
Nimbostratus
Originally I had the following irule: when HTTP_REQUEST { if { ( [HTTP::uri] equals "/" ) or ( [class match [string tolower [HTTP::uri]] starts_with dgl_aem.domain.com] ) } { pool pool_alternate.com } else { pool pool_default.domain.com } The data group list (dgl_aem.domain.com) had all the URIs for the alternate pool. The problem that has come up is that for example /legal-documents/ is defined in the data group list to (as it should) to point to the alternate pool but the URI /legal-documents/insurance needs to point to the default pool. So to allow these few exception URIs to hit the default pool before the data group was read I thought I could do this iRule: when HTTP_REQUEST { if { ( [HTTP::uri] equals "/A/documents" ) or ( [HTTP::uri] equals "/B/documents" ) or ( [HTTP::uri] equals "/C/documents" ) or ( [HTTP::uri] equals "/D/documents" ) or ( [HTTP::uri] equals "/E/documents" )} { pool pool_default_domain.com } if { ( [HTTP::uri] equals "/" ) or ( [class match [string tolower [HTTP::uri]] starts_with dgl_aem.domain.com] ) } { pool pool_alternate.com } else { pool pool_default.domain.com }
- kunjan_118660
Cumulonimbus
I need if the top IF statements match to exit the irule and use the defined pool.
Are your referring to this:
if { ( [HTTP::uri] equals "/" ) or ( [class match [string tolower [HTTP::uri]] starts_with dgl_aem.domain.com] ) } {
What is the string list in dgl_aem.domain.com expected to match here?
- JeffM
Nimbostratus
Originally I had the following irule: when HTTP_REQUEST { if { ( [HTTP::uri] equals "/" ) or ( [class match [string tolower [HTTP::uri]] starts_with dgl_aem.domain.com] ) } { pool pool_alternate.com } else { pool pool_default.domain.com } The data group list (dgl_aem.domain.com) had all the URIs for the alternate pool. The problem that has come up is that for example /legal-documents/ is defined in the data group list to (as it should) to point to the alternate pool but the URI /legal-documents/insurance needs to point to the default pool. So to allow these few exception URIs to hit the default pool before the data group was read I thought I could do this iRule: when HTTP_REQUEST { if { ( [HTTP::uri] equals "/A/documents" ) or ( [HTTP::uri] equals "/B/documents" ) or ( [HTTP::uri] equals "/C/documents" ) or ( [HTTP::uri] equals "/D/documents" ) or ( [HTTP::uri] equals "/E/documents" )} { pool pool_default_domain.com } if { ( [HTTP::uri] equals "/" ) or ( [class match [string tolower [HTTP::uri]] starts_with dgl_aem.domain.com] ) } { pool pool_alternate.com } else { pool pool_default.domain.com }
- kunjan
Nimbostratus
that for example /legal-documents/ is defined in the data group list to (as it should) to point to the alternate pool but the URI /legal-documents/insurance needs to point to the default pool.
I think "starts_with" is the one which is failing here. You can have the original logic but change "starts_with" to "contains". But your dgl shouldn't have the end forward slash. Or if really wants the first if clause to remain, do a "return" so that next following if clause doesn't execute.
- JeffM
Nimbostratus
I did change the starts_with to contains but also had to do a re-write from if/if to elseif statements to trigger script exits upon successful match. This iRule is working. Thank you for your responses. when HTTP_REQUEST { if { ( [HTTP::uri] contains "/legal/documents" ) } { pool pool_host.domain.com_80 } elseif { ( [HTTP::uri] contains "/legal-notices/documents" ) } { pool pool_host.domain.com_80 } elseif { ( [HTTP::uri] contains "/legal-families/document-library" ) } { pool pool_host.domain.com_80 } elseif { ( [HTTP::uri] contains "/legal-producer/document-library" ) } { pool pool_host.domain.com_80 } elseif { ( [HTTP::uri] contains "/producer/document-library" ) } { pool pool_host.domain.com_80 } elseif { ( [HTTP::uri] equals "/" ) or ( [class match [string tolower [HTTP::uri]] contains dgl_host.domain.com_80] ) } { pool pool_ALThost.domain.com_80 } else { pool pool_host.domain.com_80 } }
- kunjan_118660
Cumulonimbus
that for example /legal-documents/ is defined in the data group list to (as it should) to point to the alternate pool but the URI /legal-documents/insurance needs to point to the default pool.
I think "starts_with" is the one which is failing here. You can have the original logic but change "starts_with" to "contains". But your dgl shouldn't have the end forward slash. Or if really wants the first if clause to remain, do a "return" so that next following if clause doesn't execute.
- JeffM
Nimbostratus
I did change the starts_with to contains but also had to do a re-write from if/if to elseif statements to trigger script exits upon successful match. This iRule is working. Thank you for your responses. when HTTP_REQUEST { if { ( [HTTP::uri] contains "/legal/documents" ) } { pool pool_host.domain.com_80 } elseif { ( [HTTP::uri] contains "/legal-notices/documents" ) } { pool pool_host.domain.com_80 } elseif { ( [HTTP::uri] contains "/legal-families/document-library" ) } { pool pool_host.domain.com_80 } elseif { ( [HTTP::uri] contains "/legal-producer/document-library" ) } { pool pool_host.domain.com_80 } elseif { ( [HTTP::uri] contains "/producer/document-library" ) } { pool pool_host.domain.com_80 } elseif { ( [HTTP::uri] equals "/" ) or ( [class match [string tolower [HTTP::uri]] contains dgl_host.domain.com_80] ) } { pool pool_ALThost.domain.com_80 } else { pool pool_host.domain.com_80 } }
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