Forum Discussion

Hem_66900's avatar
Hem_66900
Icon for Cirrus rankCirrus
Sep 03, 2014

Redirect wildcard URI ( in the middle ) using datagroup & irule.

I would like to redirect this with a data group & irule.

Data group entry will be as below. ( I've multiple URIs that can redirected to different URLs,i just showed one Data group entry that needs to be redirected ) /us/e*/apple/mango/banana/grape.html data http://www.abc.com/rose/lilly/mo=ums.html

        Where e* can be anything starts with a letter e
        like e123,ea,eu,es1234 etc.

3 Replies

  • i understand you have to walk through data group entry one by one and perform string match. if you are processing ton of concurrent requests, it may not be a good idea.

     

  • This is one way you could do it.

    foreach item [class match -value [HTTP::path] starts_with beginning] {
       if {[HTTP::path] ends_with [class match -value $item equals ending]} {
         HTTP::redirect [class match -value $item equals redirect]
         return
       }
    }
    

    Example: /us/e*/apple/mango/banana/grape.html

    The first datagroup contains the first half of the pattern...

    datagroup: beginning

    /use/e "2345 4563 9546 4354"

    The second datagroup contains the possible endings that match the first half. These are references by the numbers from the first half match above.

    datagroup: ending

    2345 /apple/mango/banana/grape.html

    4563 /pear/apple/ranga.html

    9564 /kiwi/fruit/toast.html

    4354 /orange/orange/orange.html

    The third contains the redirects for the matching pairs. I have only included one for this example.There would be at least four to match the possible endings above.

    datagroup: redirect

    2345 http://www.abc.com/rose/lilly/mo=ums.html

    It should do what you need however you will need to test and see how well it performs for you.

    • Kevin_Davies_40's avatar
      Kevin_Davies_40
      Icon for Nacreous rankNacreous
      In a lot of cases you will only have one entry in the second datagroup that matches the first. The numbers used are really decided by you. They dont even have to be numbers just something unique to represent various endings.