Forum Discussion
Simplify irule (rather than if ,elseif, elseif ...)
Hi
Is there anyway to simplify or condense this irule?
when HTTP_REQUEST
if {[HTTP::uri] starts_with "/atm/"
or [HTTP::uri] contains "/ammcontent"
or [HTTP::uri] contains "/htmlsite"
or [HTTP::uri] contains "/publichtml"
or [HTTP::uri] contains "/crmform"
or [HTTP::uri] contains "/distsite"
or [HTTP::uri] contains "/wttw"
or [HTTP::uri] contains "/rules"
or [HTTP::uri] contains "/attributeweb"
or [HTTP::uri] contains "/contentweb" }
{ pool atm_HTTP }
Thank you
8 Replies
- kridsana
Cirrocumulus
we got many kind of irule. if we can simplify or condense it , it may help with much performance - kridsana
Cirrocumulus
And what problem if we using many "if" instead of if+elseif
like,
if {aaa}
if {bbb}
if {ccc}
- Lee_Payne_53457
Cirrostratus
I think you want something like:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::host]] { "/atm" { pool atm_HTTP } "/ammcontent*" { pool atm_HTTP } }}
You can then future proof it by redirecting based on URI and adding new lines easily.
- giltjr
Nimbostratus
switch -glob [string tolower [HTTP::uri]] { "/ammcontent*" - "/htmlsite*" - "/publichtml*" - "/crmform*" - "/distsite*" - "/wttw*" - "/rules*" - "/attributeweb*" - "/contentweb*" } {pool atm_HTTP } default {pool default_pool } } - kridsana
Cirrocumulus
Can I do like this?
when HTTP_REQUEST if {[HTTP::uri] starts_with "/atm/" or [class match [HTTP::uri] contains my_uri_datagroup] } { pool atm_HTTP }and my_uri_datagroup is include with all those uri "/.."
- Antony2015
Altostratus
Hello Teepan,
I hope this will work for you. Have you tried this ?
- Arie
Altostratus
I would recommend converting the URL to lowercase before doing the comparison. Just make sure you always enter the values you want to check for in lowercase.
So, instead of:
if {[HTTP::uri] starts_with "/atm/"[class match [HTTP::uri] contains my_uri_datagroup] }You would use:
if {[string tolower[HTTP::uri]] starts_with "/atm/"[class match [string tolower [HTTP::uri]] contains my_uri_datagroup] } - Brad_Parker
Cirrus
For scale-ability in the future if you ever needed to send traffic to other pools I would recommend creating your string data group with the URIs you want to match with values for the corresponding pool and use an iRule like this. I would also recommend setting the default pool on the virtual server itself.
when HTTP_REQUEST { if {[string tolower [HTTP::uri]] starts_with "/atm/"}{ pool atm_HTTP } elseif {[class match [string tolower [HTTP::uri]] contains "/Common/my_uri_datagroup"]}{ pool [class match -value [string tolower [HTTP::uri]] contains "/Common/my_uri_datagroup"] } }
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