Forum Discussion

F_Ibrahim_32340's avatar
F_Ibrahim_32340
Icon for Nimbostratus rankNimbostratus
Jul 05, 2017

Need help building simple iRule

Hi Guys and Girls,

 

I need to create a simple iRule but sadly even simple is hard for me. The iRule should do the following:

 

If there is an http request which does not contain or equal business/portal.html it should be forwarded to pool 1, all other extensions business/portal.* (jpeg, gif, etc) should be forwarded to pool 2.

 

Can anyone help me with this?

 

Thanks!

 

  • Hello,

    If you do not know how to create an iRule to this case, you can try an LTM policy and do the same thing, which can help you easely.

    https://support.f5.com/kb/en-us/products/big-ip_ltm/manuals/product/local-traffic-policies-getting-started-12-1-0/1.html

    https://support.f5.com/kb/en-us/products/big-ip_ltm/manuals/product/ltm-basics-11-6-0/6.html

    Anyway, You could do like this:

    e.g. 1

    when HTTP_REQUEST {
        Path is portal.hml or not begins with /business/portal.
        if { [HTTP::path] eq "/business/portal.html" ||  not ( [HTTP::path] starts_with "/business/portal." ) } {
            pool pool1
        } else {
            pool pool2
        }
    }
    

    e.g. 2

    when HTTP_REQUEST {
        Path begins with "/business/portal." and is not "/business/portal.html"
        if { [HTTP::path] starts_with "/business/portal." && [HTTP::path] ne "/business/portal.html" } {
            pool pool2
        } else {
            pool pool1
        }
    }
    

    If url is case insensitive, you may need to change it into. e.g.

    [string tolower [HTTP::path]] eq "/test.html"
    or
    [string toupper [HTTP::path]] eq "/TEST.HTML"

    Regards

  • here is the complete Irule. First make sure you set an variable with all lowercase of the path. Then compare the variable with the string in lower case.

    when HTTP_REQUEST {

     changing the path to lowercase
    set Vpath [string tolower [HTTP::path]]
    
    Path begins with "/business/portal.html"
    if { $Vpath contains "/business/portal.html" } {
        pool pool2
    } else {
        pool pool1
    }
    

    }

    • cjunior's avatar
      cjunior
      Icon for Nacreous rankNacreous

      Hi Hectorm,

       

      I'm not sure if this code will cover all conditions needed, am I wrong?

       

      If there is an http request which does not contain or equal business/portal.html it should be forwarded to pool 1, all other extensions business/portal. (jpeg, gif, etc) should be forwarded to pool 2.

       

      Respectfully

       

  • here is the complete Irule. First make sure you set an variable with all lowercase of the path. Then compare the variable with the string in lower case.

    when HTTP_REQUEST {

     changing the path to lowercase
    set Vpath [string tolower [HTTP::path]]
    
    Path begins with "/business/portal.html"
    if { $Vpath contains "/business/portal.html" } {
        pool pool2
    } else {
        pool pool1
    }
    

    }

    • cjunior's avatar
      cjunior
      Icon for Nacreous rankNacreous

      Hi Hectorm,

       

      I'm not sure if this code will cover all conditions needed, am I wrong?

       

      If there is an http request which does not contain or equal business/portal.html it should be forwarded to pool 1, all other extensions business/portal. (jpeg, gif, etc) should be forwarded to pool 2.

       

      Respectfully