Forum Discussion

Allan_66523's avatar
Allan_66523
Icon for Nimbostratus rankNimbostratus
Oct 19, 2011

Irule Creation

Hi I am new to Irules and was wondering if someone could help me out. I am looking to create an I rule that does one of the following:

 

 

If a request comes into a VIP on the F5 without WWW (ex. f5.com) add www to the request then process and forward.

 

 

 

or

 

 

If a request comes into a VIP on the F5 without WWW (ex. f5.com) send to a different vip

 

 

Thanks in advance,

 

  • e.g.

    case 1

    [root@iris:Active] config  b virtual bar list
    virtual bar {
       snat automap
       pool foo
       destination 172.28.17.33:http
       ip protocol tcp
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@iris:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
            if {not ([string tolower [HTTP::host]] starts_with "www")} {
                    HTTP::header replace Host "www.[HTTP::host]"
            }
    }
    }
    
    ---------------------------------------------------------------
    New TCP connection 1: 172.28.16.50(44422) <-> 172.28.17.33(80)
    1319032099.4764 (0.0013)  C>S
    ---------------------------------------------------------------
    HEAD / HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: abc.com
    Accept: */*
    
    ---------------------------------------------------------------
    New TCP connection 2: 10.10.72.30(44422) <-> 10.10.70.110(80)
    1319032099.4769 (0.0003)  C>S
    ---------------------------------------------------------------
    HEAD / HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: www.abc.com
    Accept: */*
    
    

    case 2

    [root@iris:Active] config  b virtual bar list
    virtual bar {
       snat automap
       pool foo
       destination 172.28.17.33:http
       ip protocol tcp
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@iris:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
            if {not ([string tolower [HTTP::host]] starts_with "www")} {
                    virtual barbar
            }
    }
    }
    [root@iris:Active] config  b virtual barbar list
    virtual barbar {
       snat automap
       pool foo
       destination 172.28.17.44:http
       ip protocol tcp
    }
    
    ---------------------------------------------------------------
    New TCP connection 1: 172.28.16.50(34836) <-> 172.28.17.33(80)
    1319032322.1664 (0.0005)  C>S
    ---------------------------------------------------------------
    HEAD / HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: abc.com
    Accept: */*
    
    ---------------------------------------------------------------
    New TCP connection 2: 172.28.16.50(34836) <-> 172.28.17.44(80)
    1319032322.1665 (0.0000)  C>S
    ---------------------------------------------------------------
    HEAD / HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: abc.com
    Accept: */*
    
    ---------------------------------------------------------------
    New TCP connection 3: 10.10.72.30(34836) <-> 10.10.70.110(80)
    1319032322.1704 (0.0038)  C>S
    ---------------------------------------------------------------
    HEAD / HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: abc.com
    Accept: */*
    
    
  • i don't know. LOL

     

     

    you may interest this article.

     

     

    iRules Optimization 101 - 05 - Evaluating iRule Performance by Deb

     

    http://devcentral.f5.com/Tutorials/TechTips/tabid/63/articleType/ArticleView/articleId/123/iRules-Optimization-101--05--Evaluating-iRule-Performance.aspx

     

     

    anyway, when i write irule, i prefer the one which is simpler and easy to maintain. i do not see whole config, so i think both are not so different.

     

     

    this is just my personal opinion!