Forum Discussion

MrGlass_204919's avatar
MrGlass_204919
Icon for Nimbostratus rankNimbostratus
Sep 01, 2017

HTTP REQUEST - Some Assitance

Hi Folks,

I currently have an irule that is redirecting extensions behind the business/portal to a pool.

when HTTP_REQUEST { 
    log local0. "Request: [HTTP::uri]" 
    switch -glob [string tolower [HTTP::uri]] { 
    "/business/portal*.js" -
    "/business/portal*.js\?*" -
    "/business/portal*.svgz" -
    "/business/portal*.svgz\?*" -
    "/business/portal*.png" -
    "/business/portal*.png\?*" {
                                        log local0. "Static"
                                        Static content to DMZ
                                        pool EXP_business.x.x-static pool_HTTP 
                                        persist none
                                         Disable serverside SSL 
                                        SSL::disable serverside
                                         Change host header to x-client-x.x.x
                                            if { [HTTP::host] equals "business.x.x"} {
                                                if {[HTTP::uri] contains "business/portal/"} {
                                                     HTTP::header replace "Host" "x-client-x.x.x"                         
                                                     log local0. "Rewrite business portal" 
                                                }

                                            }
            } 
            default {

                                             Dynamic Content to seal
                                            pool EXP_business.x.x-https_pool 
                                            log local0. "Default"

            }
    }
`


}

This irule is however insufficient seeing that everytime there is a new context we need to modify the irule.
Thus i have created a new irule that is now working on a NOT parameter: IF path begins with "/business/portal" 
and is not "/business/portal.html" 

`when HTTP_REQUEST {
    log local0. "Request: [HTTP::uri]" 
    switch -glob [string tolower [HTTP::uri]] {
        "business/portal." && [HTTP::path] ne "busines/portal.*html" } {
         pool EXP_business.x.x-https_pool
         log local0. "Default"
    } else {
    Static content to DMZ
     Disable serverside SSL 
     Change host header to x-client-x.x.x
        pool EXP_business.x.x-static-pool_HTTP
        persist none
        SSL::disable serverside
        if { [HTTP::host] equals "business.x.x"} {
        if {[HTTP::uri] contains "business/portal/"} {
        HTTP::header replace "Host" "x-client-x.x.x"                         
                log local0. "Rewrite business portal" 
            }
       }
  }

}

Can you guys tell me if this will work? Next monday will test the irule and i am trying to do it good in one go.

4 Replies

  • Hi

    switch does not support multiple condition.

    You have to do that:

    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::path]] {
            "/busines/portal.*html" {same action than default}
            "/business/portal.*" {
                other actions
            } 
            default {actions}
        }
    }
    
    or you use if / then / elseif / else
    
  • Hi Stan,

    Thanks for your answer. I am a total beginner on irules so could you please check if this is correct?

    when HTTP_REQUEST {
    switch -glob [string tolower [HTTP::path]] {
        "/business/portal.*html" {
            pool EXP_business.x.x-static-pool_HTTP
            persist none
            SSL::disable serverside
        }
            switch { [HTTP::host] equals "business.x.x"} {
            {[HTTP::uri] contains "business/portal/"} {
            HTTP::header replace "Host" "x-y-exp.x.x"                         
                        log local0. "Rewrite business portal" 
    
           "/business/portal.*" {
           pool EXP_business.x.x-https_pool
           log local0. "Default"
        } 
    
    }
    

    }

    • Stanislas_Piro2's avatar
      Stanislas_Piro2
      Icon for Cumulonimbus rankCumulonimbus

      Hi,

      your irule format is wrong. you merge if / then / else and switch commands, which worth work.

      switch format is :

      switch [options like --glob, ...] string {
          pattern1 { 
              actions for pattern1
          }
          pattern2 { 
              actions for pattern2
          }
          pattern3 -
          pattern4 { 
              actions for pattern3 and pattern4
          }
          default {
              actions if no previous pattern matches
          }
      }
      

      patterns are string (no condition) which can support wildcard if

      -glob
      option was set

      if / then / else format is:

      if {condition1} {
          actions for condition1
      } elseif {condition2} {
          actions for ondition2
      } else {
          actions if no previous condition matches
      }
      

      condition can be

      [HTTP::uri] equals "/portal/"

  • There is an irule builder tool you can download for help with irules.