Forum Discussion

NhatMinh-TSV_18's avatar
NhatMinh-TSV_18
Icon for Nimbostratus rankNimbostratus
Jan 28, 2015

Convert rule on Apache to iRule

Hi all, I have a customer using apache to load balancing, on this device, they have a rule

 

^/thongtin/([0-9]+)/(.*)/?$ /wps/portal/abc/newsdetails?newsId=$1 [L,PT]

 

Plz help me to change this rule to iRule. Tks all,

 

8 Replies

  • My suggestion would be to check out the iRules 101 articles to help learn how best to build iRules, and then look at the tcl scan command to parse your URI (Regex can be costly on resources, so only use it when you need to).

    From there, you should be able put together an iRule that meets your needs. Looks like your requirements are any URI that matches

    ^/thongtin/([0-9]+)/(.*)/?$
    needs to go to
    /wps/portal/abc/newsdetails?newsId=$1
    , where
    $1
    is what's found in the
    [0-9]+
    part of the uri.

    If you have trouble writing the iRule, I can try to help you out.

  • hi Michael J, You are right about this URI. Please help me to write this iRule. Tks you,

     

  • So, with regexp, you could use an expression like:

    if {[regexp {^/thongtin/([0-9]+)/.*/?$} [string tolower [HTTP::uri]] match id]} {
        HTTP::redirect "/wps/portal/abc/newsdetails?newsId=$id"
    }
    

    I'll try to put together the

    scan
    version later.

  • When I use iRule

    when HTTP_REQUEST

    {if {[regexp {^/thongtin/([0-9]+)/(._)/?$} [string tolower [HTTP::uri]] match id]}

    HTTP::redirect "/wps/portal/abc/newsdetails?newsId=$id"}

    I received a error:

    01070151:3: Rule [/Common/aBC] error: /Common/aBC:2: error: [missing a script after "if"][]