Forum Discussion

Mark_2014_16996's avatar
Mark_2014_16996
Icon for Nimbostratus rankNimbostratus
Sep 16, 2014

How to combine 2 iRules

I need help combining 2 iRules:

iRule 1:

when HTTP_REQUEST { if { [HTTP::host] equals "www.webpage.com" } { if { [HTTP::path] starts_with "/access/" } { log local0. "host=[HTTP::host] path=[HTTP::path] action=allow" return } } log local0. "host=[HTTP::host] path=[HTTP::path] action=reject" reject }

iRule 2

when HTTP_REQUEST { if { [HTTP::uri] contains "client_id=connection" } { log local0. "uri=[HTTP::uri] action=allow" return } else {

     log local0.  "Rejected"
     reject
  }

}

Thanks, Mark

9 Replies

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    You could simply move the if-statement from the second rule into the first rule. However, there's a non-conditional "reject" command in the first rule that will reject all requests. Is this intentional?

    rule 1:

    when HTTP_REQUEST { 
    
        if { [HTTP::host] equals "www.webpage.com" } { 
    
            if { [HTTP::path] starts_with "/access/" } { 
    
                log local0. "host=[HTTP::host] path=[HTTP::path] action=allow" return 
    
            } 
    
        } 
    
        log local0. "host=[HTTP::host] path=[HTTP::path] action=reject" 
    
        reject 
    
    }
    
  • Thanks!

     

    I need the iRule to just allow URL: www.webpage.com/access/.....client_id=connection

     

    And reject all if it doesn't have host, www.webpage.com, URI, /access and string cleint_id=connection within the URL.

     

    Another words, I'm just allowing 1 URL.

     

    I tried moving the if statement but I got error messages.

     

  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    This should do it, then:

    when HTTP_REQUEST { 
    
        if { ( [HTTP::query] contains "client_id=connection" ) && ( [HTTP::path] starts_with "/access/" ) && ( [HTTP::host] equals "www.webpage.com" ) } { 
    
            log local0. "uri=[HTTP::uri] action=allow" 
    
        } else {
    
            log local0.  "Rejected"
    
            reject
    
        }
    
    }
    
  • Arie's avatar
    Arie
    Icon for Altostratus rankAltostratus

    Better:

    when HTTP_REQUEST { 
    
        if { !( [HTTP::query] contains "client_id=connection" && [HTTP::path] starts_with "/access/" && [HTTP::host] equals "www.webpage.com" ) } { 
    
            reject
    
        }
    
    }
    
    • Arie's avatar
      Arie
      Icon for Altostratus rankAltostratus
      Great! Would you mind marking my reply as the answer?
  • Sure...... but not sure how to do that but I'm assuming you mean to click the 'Check mark'?