Forum Discussion

Neil_66348's avatar
Neil_66348
Icon for Nimbostratus rankNimbostratus
Jan 24, 2010

HTTP URI to multiple pools

Hi guys ,

 

 

Fairly new to iRules and TCL , would like to have the ability to have different uri's for the same site directed to different pools.

 

 

Essentially :

 

www.company.com - goes to one pool

 

www.company.com/account goes to another pool - (but www.company.com can have other paths)

 

www.company.com/service - goes to another pool

 

 

Anything not specified goes to the default pool for the listner.

 

 

Pieced together this example , (which doesn't work) can anyone assist.

 

 

when HTTP_REQUEST {

 

switch [string tolower [HTTP::host]] {

 

"www.company.com/account" {

 

Rewrite URI to /account/path/index.html

 

if {[HTTP::path] eq "/"}{

 

HTTP::uri "/account/path/index.html"

 

}

 

Use pool1

 

pool pool1

 

}

 

"www.company.com/service" {

 

Rewrite / to /service/path/index.html

 

if {[HTTP::path] eq "/"}{

 

HTTP::uri "/service/path/index.html"

 

}

 

Rewrite URI to www.company.com

 

 

Use pool2

 

pool pool12

 

}

 

}

 

}

 

 

Thanks

 

 

Neil

3 Replies

  • Hi Neil,

     

     

    There are a few issues. You're using switch to check the host header value, but then using switch cases which include the URI. This will never match as the host header doesn't contain the URI. You could fix this by either changing the switch to check "[string tolower [HTTP::host]][HTTP::uri]" or removing the /account and /service from the switch cases. The latter option would mean you could remove the second www.company.com entry. Also, you're checking for a path of / in each switch case. If the switch case is matching on a specific URI, the path will never be just /.

     

     

    If you clarify what logic you want to implement, we can help you write the iRule to fit it.

     

     

    Aaron
  • Neil,

     

     

    It doesn't apper that there are multiple host names involved so you only need to match on the HTTP::uri.

     

     

    when HTTP_REQUEST {

     

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

     

    No path goes to pool-1

     

    / {

     

    pool pool-1

     

    }

     

    paths that start with /account go to pool-2

     

    /account* {

     

    pool pool-2

     

    }

     

    paths that start with /service go to pool-3

     

    /service* {

     

    pool pool-3

     

    }

     

    all other requests go to pool-4

     

    default {

     

    pool pool-4

     

    }

     

    }

     

    }

     

     

    Also, it is hard to tell from your example but, it looks like you are also trying to define the "default context" or "default document" for a given path. i.e. If request comes in for /account then rewrite or redirect to /account/path/index.html.

     

     

    When I get requests like this from the server guys I usually tell them that is the server's job (:-D) to define the default context/document but, it can be done on the LTM. First I would sugest a redirect and NOT a rewrite. Also, you just have to be careful to to use an effective "equals" and not a "starts_with" or you will end up with an infinite redirect. Let us know if that is what you are trying to do and we can help with the irule.

     

     

    Joe
  • hi joe ,

     

     

    Thats great!

     

     

    It appears to do a redirect to alternate pools , but I do have a few requirements to rewrite to the default context of a web server for some 3rd party web services. Which we can't change.

     

     

    So we have the website , www.company.com for the default pool which is fine.

     

    www.company.com/account

     

     

    paths that start with /account go to pool-2

     

    /account* {

     

    pool pool-2

     

     

    The problem is the web server for account requires the users to hit the root as opposed to a sub folder. So we're getting back page not found for http://www.company.com/account (because the pool2 server is seeing the request for */account whereas its expecting /* at the top level.

     

     

    I'm guessing I need to do a rewrite for /account* to pass that to the pool-2 server actually as /* any pointers on how to do that...

     

     

    Many thanks

     

     

    neil