Forum Discussion

andy_22730's avatar
andy_22730
Icon for Nimbostratus rankNimbostratus
Dec 19, 2008

Use redirect and pools in same iRule?

I'm trying to build one irule that has all my logic in it, it will parse the URI of the request and send some URIs to a pool, but send others to external servers via HTTP::REDIRECT.

 

 

I don't seem to be able to do this in a single rule.

 

 

Should I use 2 rules? Is that slower?

 

 

Here is the logic of the rules:

 

 

 

 

when HTTP_REQUEST {

 

 

if {[HTTP::uri] starts_with "/foo"} {HTTP::redirect "http://foo.com"}

 

if {[HTTP::uri] starts_with "/bar"} {pool bar-pool}

 

}

 

 

 

I can create this irule, but anytime it matches to the bar, I get a tmm error about redirecting.... and it never redirects to the member of the pool.

 

4 Replies

  • TCL gets a little finicky with spacing, plus, you probably want an elseif instead of an if on that second conditional. Try this:

       
       when HTTP_REQUEST {   
         if { [string tolower [HTTP::uri]] starts_with "/foo" } {   
           HTTP::redirect "http://foo.com" 
         } elseif { [string tolower [HTTP::uri]] starts_with "/bar" } {   
             pool bar-pool   
         } else {   
             pool default-pool   
         }   
       }    
       

    Post back your error if this doesn't help you
  • Excellent, this worked. WHat I ended up using:

     

     

    when HTTP_REQUEST {

     

    if { [string tolower [HTTP::uri]] starts_with "/blog" } {

     

    pool my-aws-blog-pool

     

    } elseif { [string tolower [HTTP::uri]] starts_with "/a1" } {

     

    HTTP::redirect "http://wwwa1.somwebsite.com/"

     

    } elseif { [string tolower [HTTP::uri]] starts_with "/a2" } {

     

    HTTP::redirect "http://wwwa2.somwebsite.com/"

     

    } else {

     

    HTTP::redirect "http://wwwa1.somwebsite.com/"

     

    }

     

    }

     

     

     

    And this does exactly what I want.

     

     

     

    My only lingering question now (and I know it's not an irule question but I'll throw it out there) is how to use a DNS name for a node in a pool... I'm lucky that i can get away in this case without using one, but we have servers using virtual names and so I will need to hit an Amazon EC2 server someday using a hostname in a pool.... but thanks the above help, it works.

     

     

    BTW, that pool is made up of virtual servers in amazon, so far it's working nicely.

     

     

     

     

     

  • Check this thread for that capability:

     

     

    http://devcentral.f5.com/Default.aspx?tabid=53&forumid=5&tpage=1&view=topic&postid=65466546

     

    Click here