Forum Discussion
Amit585731
Feb 28, 2016Nimbostratus
Regarding nested if irule.
Hi Team,
I am struggling to get a irule working where I am trying to implement nested if for a project. The user want us to implement irule base on header where we have 3 pools: pool1, pool2 and pool3. The user want us to implement:
- abc.com/test.html should be routed to pool1 and pool2 * if url include username=testuser then request should be routed to pool1 * if url include username=testuser1 then request should be routed to pool2
- abc.com/test1.html should be routed to pool3 * else all users should be routed to pool3.
Thanks..
- nitass_89166Noctilucent
i used switch here because i think it is a bit easier to read.
configuration [root@ve11b:Active:In Sync] config tmsh list ltm rule qux ltm rule qux { when HTTP_REQUEST { log local0. "uri = [HTTP::uri]" switch [string tolower [HTTP::path]] { "/test.html" { switch [string tolower [URI::query [HTTP::uri] username]] { "testuser" { do something log local0. "/test.html with username=testuser" } "testuser1" { do something log local0. "/test.html with username=testuser1" } default { do something log local0. "/test.html without username or with username but testuser/testuser1" } } } "/test1.html" { do something log local0. "/test1.html" } default { do something log local0. "default" } } } } /var/log/ltm Feb 28 22:32:12 ve11b info tmm[14159]: Rule /Common/qux : uri = /test.html?username=testuser Feb 28 22:32:12 ve11b info tmm[14159]: Rule /Common/qux : /test.html with username=testuser Feb 28 22:32:17 ve11b info tmm[14159]: Rule /Common/qux : uri = /test.html?username=testuser1 Feb 28 22:32:17 ve11b info tmm[14159]: Rule /Common/qux : /test.html with username=testuser1 Feb 28 22:32:25 ve11b info tmm1[14159]: Rule /Common/qux : uri = /test.html?username=somebody Feb 28 22:32:25 ve11b info tmm1[14159]: Rule /Common/qux : /test.html without username or with username but testuser/testuser1 Feb 28 22:32:48 ve11b info tmm[14159]: Rule /Common/qux : uri = /test.html?surname=something Feb 28 22:32:48 ve11b info tmm[14159]: Rule /Common/qux : /test.html without username or with username but testuser/testuser1 Feb 28 22:32:56 ve11b info tmm1[14159]: Rule /Common/qux : uri = /test1.html Feb 28 22:32:56 ve11b info tmm1[14159]: Rule /Common/qux : /test1.html Feb 28 22:33:04 ve11b info tmm1[14159]: Rule /Common/qux : uri = /abc.html Feb 28 22:33:04 ve11b info tmm1[14159]: Rule /Common/qux : default
- Amit585731NimbostratusThanks Nitass for your help.. Just wanted to check if you have one irule where nested if is working? I don't know the irule I created seems correct but it is not working...
- nitass_89166Noctilucentcan you post it? so, folk here can take a look and give some feedback.
- nitassEmployee
i used switch here because i think it is a bit easier to read.
configuration [root@ve11b:Active:In Sync] config tmsh list ltm rule qux ltm rule qux { when HTTP_REQUEST { log local0. "uri = [HTTP::uri]" switch [string tolower [HTTP::path]] { "/test.html" { switch [string tolower [URI::query [HTTP::uri] username]] { "testuser" { do something log local0. "/test.html with username=testuser" } "testuser1" { do something log local0. "/test.html with username=testuser1" } default { do something log local0. "/test.html without username or with username but testuser/testuser1" } } } "/test1.html" { do something log local0. "/test1.html" } default { do something log local0. "default" } } } } /var/log/ltm Feb 28 22:32:12 ve11b info tmm[14159]: Rule /Common/qux : uri = /test.html?username=testuser Feb 28 22:32:12 ve11b info tmm[14159]: Rule /Common/qux : /test.html with username=testuser Feb 28 22:32:17 ve11b info tmm[14159]: Rule /Common/qux : uri = /test.html?username=testuser1 Feb 28 22:32:17 ve11b info tmm[14159]: Rule /Common/qux : /test.html with username=testuser1 Feb 28 22:32:25 ve11b info tmm1[14159]: Rule /Common/qux : uri = /test.html?username=somebody Feb 28 22:32:25 ve11b info tmm1[14159]: Rule /Common/qux : /test.html without username or with username but testuser/testuser1 Feb 28 22:32:48 ve11b info tmm[14159]: Rule /Common/qux : uri = /test.html?surname=something Feb 28 22:32:48 ve11b info tmm[14159]: Rule /Common/qux : /test.html without username or with username but testuser/testuser1 Feb 28 22:32:56 ve11b info tmm1[14159]: Rule /Common/qux : uri = /test1.html Feb 28 22:32:56 ve11b info tmm1[14159]: Rule /Common/qux : /test1.html Feb 28 22:33:04 ve11b info tmm1[14159]: Rule /Common/qux : uri = /abc.html Feb 28 22:33:04 ve11b info tmm1[14159]: Rule /Common/qux : default
- Amit585731NimbostratusThanks Nitass for your help.. Just wanted to check if you have one irule where nested if is working? I don't know the irule I created seems correct but it is not working...
- nitassEmployeecan you post it? so, folk here can take a look and give some feedback.
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects