Forum Discussion

Aurel's avatar
Aurel
Icon for Cirrus rankCirrus
Oct 23, 2013

Irule and regex inspired from apache like regex

Hi,

 

I'm migrating a reverse proxy apache conf to BigIP. I had powerful line that matches 192 urls cases. The issue is that the best i've found until now, is really not convenient at all with BigIP. I'm actually using an Irule that calls a DataGroup containing those 192 lines. Here's the apache line : RewriteRule ^/A(B|C)DEF/test-(10|20|30|40|50|60)/(one|two|three|four|five|six|seven|eight)/(2013|2014)/(.) This can handle (2682 = 192 cases) in one line. In my BigIP configuration, i had to use DataGroups and write down all those cases. Does anyone think about another way to manage this without Datagroups ?

 

Thanks a lot for any help Aurel

 

  • What are you looking to actually do on a match and can I assume you're looking to match the URI? I'd imagine the 'matches_regex' command would work well here.

     

  • Agreed. Something like this:

    when HTTP_REQUEST {
        if { [HTTP::uri] matches_regex {^/A(B|C)DEF/test-(10|20|30|40|50|60)/(one|two|three|four|five|six|seven|eight)/(2013|2014)/(.)} } {
            log local0. "match"
        } else {
            log local0. "no match"
        }
    }
    
  • Hi Kevin, Thanks a lot for your reply. Yes, it is about URI matches. Your code looks perfect. I also need to rewrite, do you maybe know how to get the following ?

     

    http://webserver_name-$2-A$1DEF/$4/$5

     

  • I don't think a lookahead/back reference will work with matches_regex, but this will:

    if { [regexp {^/A(B|C)DEF/test-(10|20|30|40|50|60)/(one|two|three|four|five|six|seven|eight)/(2013|2014)/(.)} $uri all a b c d e] == 1 } {
        log local0. "http://webserver_name-${b}-A${a}DEF/${d}/${e}"
    }