irule to switch uri based of a class file

Hi there, I am beginner in terms of coding irules. I seek your help in coding an irule. My scenario is I need to switch multiple uris. I kind of know how to do it usinga switch statement. But as part of standards followd at my work place. I need to code something generic which can be used across different platforms. So I need help how to use a class file to trigger uri swictc. Thanks for the help.

--KG

From a data-group, you don’t need to use a switch statement. Below is something I use:

ltm data-group internal url-redirect-class {
    records {
        /from1 {
            data /to1
        }
        /from2 {
            data /to2
        }
    } 
}

ltm rule redirect-rule {
    when HTTP_REQUEST {
      set path [string tolower [HTTP::path]]
      set redirect_url [class match -value -- $path equals url-redirect-class]
      if { $redirect_url ne "" } {
         HTTP::redirect $redirect_url
         return
      }
   }
}

From a data-group, you don’t need to use a switch statement. Below is something I use:

ltm data-group internal url-redirect-class {
    records {
        /from1 {
            data /to1
        }
        /from2 {
            data /to2
        }
    } 
}

ltm rule redirect-rule {
    when HTTP_REQUEST {
      set path [string tolower [HTTP::path]]
      set redirect_url [class match -value -- $path equals url-redirect-class]
      if { $redirect_url ne "" } {
         HTTP::redirect $redirect_url
         return
      }
   }
}

If you are looking to switch (or route) traffic to different pools based on the URI you can use and irule simliar to this: when HTTP_REQUEST { set uri [string tolower [HTTP::uri]] switch -glob $uri { /uri1* { pool http_pool1 } /uri2* { pool http_pool2 } /uri3* - /uri4* - /uri5* { pool http_pool3 } default { pool http_pool4 } } }

If you are looking to switch (or route) traffic to different pools based on the URI you can use an irule simliar to this:

when HTTP_REQUEST {
  set uri [string tolower [HTTP::uri]]
  switch -glob $uri {
    /uri1* { 
      pool http_pool1
    }
    /uri2* {
      pool http_pool2
    }
    /uri3* -
    /uri4* -
    /uri5* {
      pool http_pool3
    } default {
      pool http_pool4
    }
  }
}

Thanks verymuch Joe

Thanks very much Uni

Thanks very much Uni