Forum Discussion

7 Replies

  • Try this:

    
    when HTTP_REQUEST {
       switch -glob [string tolower [HTTP::uri]] {
          "/url1" {
             pool pool1  
          }
          "/url2" {
             pool pool2
          }
          default {
             pool pool1  
          }
       }
    }

    Kevin
  • Again, forgive the stupidity here.

     

     

    I have a pool of 2 servers calle "web".

     

     

    What would be the syntax that I would place in the iRule that would load balance to web traffic?

     

     

    Thanks
  • This is assuming that you have more than one pool of web servers, otherwise configure the virtual server profile to point to a single defined pool on the resources tab.

    
    when HTTP_REQUEST {
       switch -glob [string tolower [HTTP::uri]] {
          "/url1" {
             pool web
          }
          "/url2" {
             pool web2
          }
          default {
             pool web
          }
       }
    }

    "default" should point to whichever pool you want traffic to go to if the uri is different than those defined in the statement.
  • Along those same lines, I need to retain the full URI coming in. So, url1/otherfile.html also needs to be directed to pool web, but keep it's full path. Would this rule above still be valid?

     

  • Also, how do I handle someone coming in as http://www.mysite.com/ with no URI, I need a URI of "/" to redirected to correct pool as well.
  • The uri won't be affected by the load balancing, so the server will get the whole thing. There's two ways to catch the base "/", using this structure, that I can think of. Perhaps one of the gurus can confirm this:

    1. the "default" case will catch everything not specifically defined, including the "/".

    2.

    
    when HTTP_REQUEST {
       switch -glob [string tolower [HTTP::uri]] {
          "/url1*" {
             pool web
          }
          "/url2*" {
             pool web2
          }
          "/" {
             pool web
          }
          default {
             pool web
          }
       }
    }

    I threw the "*" in after the uri in case there's additional text after it.
  • if you have a lots of different uri to filter you should have a look at creating class with the findclass commands: Click here

     

     

    Usually using a class is more eficient when you have more than 100 different data to filter