Forum Discussion

Steve-S_87321's avatar
Steve-S_87321
Icon for Nimbostratus rankNimbostratus
Aug 30, 2007

I-rule to redirect using regular expression

Hello,

 

 

I need to know how to write an irule to redirect to a server using port 8080 if a keyword or regular expression is included in the uri. Without the keyword it should go to the same server with port 80.

 

 

Is there an irule already posted that fits this type of solution that I can edit ?

 

 

Thanks,

 

 

Steve

4 Replies

  • Hi Steve,

    You can create a pool for the servers listening on port 80 and one for port 8080. You can then use a rule with string comparisons (starts_with, contains, ends_with) or a regex using matches_regex, to determine which pool to send the request to. Here is an example:

    
    if (http_uri starts_with "/some_uri"){
       use pool port_80_pool
    } elseif (http_uri matches_regex "(?:some regex)"){
       use pool port_8080_pool
    } else {
       use pool default_pool
    }

    Aaron
  • The following string is being used -

     

    http://bsccsupplierpayables2.sysco.com/imageserver/getimage?folders=1463,52c,52b,52b,52b,52b&docids=1ba54,788a5,1fb73,1fb74,1fdf2,1fdf7

     

     

    I have tried two different irules and neither works. Please help. The keyword that changes is getimage and so that is what I am trying

     

    to use. It seems like the irule is not catching it. The 8080 pool references the server using port 8080. The 80 pool references the same server but using port 80. If it works correctly a PDF file will be called and load. When it doesn't I get an invalid file request so it is easy to test.

     

     

    First version -

     

     

    if (tolower(http_uri) contains "getimage") {

     

    use pool bscc.sysco.com-8080

     

    }

     

    else {

     

    use pool bscc.sysco.com-80

     

    }

     

     

    2nd version -

     

     

    if (http_uri contains "getimage") {

     

    use pool bscc.sysco.com-8080

     

    }

     

    else if (http_uri matches_regex "(reportNames)") {

     

    use pool bscc.sysco.com-8080

     

    }

     

    else if (http_uri matches_regex "(reportParams)") {

     

    use pool bscc.sysco.com-8080

     

    }

     

    else if (http_uri matches_regex "(getReport)") {

     

    use pool bscc.sysco.com-8080

     

    }

     

    else if (http_uri matches_regex "(getimage)") {

     

    use pool bscc.sysco.com-8080

     

    }

     

    else {

     

    use pool bscc.sysco.com-80

     

    }

     

     

  •  

    Using the following string, the keyword in the url "getimage" is not being picked up by the rule. Does anyone know a different way to key on that keyword to use a particular pool other than the options already suggested ? Please help if possible.

     

     

    http://bsccsupplierpayables2.sysco.com/imageserver/getimage?folders=1463,52c,52b,52b,52b,52b&docids=1ba54,788a5,1fb73,1fb74,1fdf2,1fdf7
  • Both rule are straightforward enough and should work. With the first rule, are you sure that the request is being sent to the wrong pool? Can you add logging to see?

    Here's an example:

    
    if (tolower(http_uri) contains "getimage") {
       log "matched: client" + client_addr + ":" + client_port + " " + http_host + http_uri
       use pool bscc.sysco.com-8080
    }
    else {
       log "didn't match: client" + client_addr + ":" + client_port + " " + http_host + http_uri
       use pool bscc.sysco.com-80
    }

    Aaron