Forum Discussion

John_41578's avatar
John_41578
Icon for Nimbostratus rankNimbostratus
Aug 31, 2009

iRule that allows passing parameters

Hi,

 

 

Newbie here trying to figure things out. I have an iRule set as follows (condensed for brevity, actual paths removed for security):

 

 

when HTTP_REQUEST {

 

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

 

"/foo" { pool content_pool }

 

"/foo/*" { pool content_pool }

 

default { pool pool_main_site }

 

}

 

}

 

 

What I want is for all requests for "/foo" and "/foo/*" to go to the content_pool while everything else goes to the main pool. I originally had "/foo*" but then "/foobar" was getting routed as well, which I didn't want. This rule works fine except for one problem: when parameters are passed to "/foo" the request goes to the default pool. For example...

 

 

This does not route to the content pool but should:

 

http://example.com/foo?i=1

 

 

These work as expected (route to content pool):

 

http://example.com/foo

 

http://example.com/foo/page

 

http://example.com/foo/page?i=1

 

 

Note that all pages may or may not have parameters passed, and these URIs should always route to the content pool regardless.

 

 

Also note that I have about 10 pages/paths that I need to do this with, not just foo. So also let me know if there's a cleaner, better, easier way to say "these 10 pages, plus everything under them, with or without parameters."

 

 

Thanks in advance,

 

John

3 Replies

  • Hi John,

    You can check the path (URI minus the query string) using HTTP::path (Click here) instead of HTTP::uri in your switch statement. This will allow you to ignore the query string.

    Also, for switch statements, if multiple cases use the same action, you can group them using the hyphen:

     
     when HTTP_REQUEST { 
        switch -glob [string tolower [HTTP::path]] { 
           "/foo"- 
           "/foo/*" { pool content_pool } 
           default { pool pool_main_site } 
        } 
     }  
     

    Aaron