Forum Discussion

Tom_Thunem_9204's avatar
Tom_Thunem_9204
Icon for Nimbostratus rankNimbostratus
Jul 24, 2013

large number of redirects

our application group has 142 redirects they want added to into an iRule. i was wondering what the most effiecient method might be. i am currently using this syntax for many of our redirects and hestiate to build a piece of logic that contains 142 different redirects... is this still the best option?

 

 

when HTTP_REQUEST {

 

switch -glob [string tolower [HTTP::uri]] {

 

"/something*" {

 

HTTP::redirect "http://our-domain.com/some/URI/values"}

 

"/something-else*" {

 

HTTP::redirect http://our-domain.com/some/other/URI/values }

 

"/and-so-on*" {

 

HTTP::redirect ""}

 

and so on...

 

5 Replies

  • Hi Tom,

     

     

    I think that you are on the right track with the Switch Command. Unless you wanted to make a more generic iRule that uses a Datagroup to store the URI and Redirect Locations to make it simpler to manage (then you would just manage the Datagroup instead of a large iRule).
  • Michael,

     

     

    I have yet to use a datagroup. Can you show me an example of the irule and the datagroup i would use to solve my problem? I wasn't able to apply the example i found on askf5 to my particular problem.

     

     

    Thanks
  • If I may add, you have to consider whether you want to manage 142 patterns via a table structure or within procedural code. My money is on the data group option.
  • Can anyone show me how i might apply my problem to a datagroup? i have yet to use one, so i am unclear. I wasn't able to apply the example i found on askf5 to my particluar problem.

     

     

    thanks
  • Sure.

    Step 1: create a data group (LTM GUI: iRule | Data Group List | Create). Enter a name (example "my_test_dg"), select "String" type, and start entering strings and values. Example:

    "/something-else" := "http://our-domain.com/some/other/URI/values"

    "/something" := "http://our-domain.com/some/URI/values"

    "/and-so-on" := "http://our-domain.com/and/so/on"

    ** I would order these from most to least specific if the URIs start with the same string values.

    Step 2: Create the iRule:

    
    when HTTP_REQUEST {
         if { [class match [string tolower [HTTP::uri]] starts_with my_test_dg] } {
              HTTP::redirect [class match -value [string tolower [HTTP::uri]] starts_with my_test_dg]
         }
    }