Forum Discussion

Manuel_Rodrigu2's avatar
Manuel_Rodrigu2
Icon for Nimbostratus rankNimbostratus
Jun 25, 2008

Redirect to a different folder hosted by a different pool

Hi there,

 

 

Hope this can be done with an iRule. Basically when I receive requests for http://www.abc.com/hello I need to redirect them to http://www.abc.com/hello_1 hosted on a different pool, not the default.

 

 

Is it possible with an iRule?

 

 

Thanks

 

 

Manuel
  • Hi Manual,

    The following is VERY simple example of redirect

     
     when HTTP_REQUEST { 
         if {HTTP::uri eq "hello" } { HTTP::redirect "http://www.abc.com/hello_1" } 
     } 
     

    I hope this helps

    CB

  • Hi cmbhatt,

     

     

    Thanks for the quick reply. Yes that would work if hello_1 was hosted by the same pool/servers. The problem here is that we need to send that request to a different pool (not the default) and the host is the same (www.abc.com).

     

     

    Thanks again.

     

     

    Manuel
  • Hi Manuel,

    You can try this:

     
      when HTTP_REQUEST {  
          if {[string tolower [HTTP::uri]] equals "/hello" } {  
                HTTP::uri "/hello_1" 
                 pool my_other_pool 
               } else { 
                pool my_default_pool 
               } 
     } 
      
     

    Regards.
  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    It's not clear whether you want to redirect or re-write the URI. josantia's solution re-writes the URI, but only for exactly that URI.

    If you want to re-write the existing URI by simply replacing the name of the first directory, you can do it like this:
     when HTTP_REQUEST {   
         if {[getfield [string tolower [HTTP::uri]] "/" 2] equals "hello" } {   
            HTTP::uri [string map {"/hello" "/hello_1"} [HTTP::uri]]   
            pool my_other_pool    
         } else {    
            pool my_default_pool    
         }   
       }   
       

    If you want to redirect the same way (preserving the URI), you can do it like this:
     when HTTP_REQUEST {   
         switch -glob [string tolower [HTTP::uri]] {   
            "/hello1*" { pool my_other_pool }   
            "/hello*" { HTTP::redirect "http://[HTTP::host]/hello_1[substr [HTTP:uri] 6]" }   
            default { pool my_default_pool }   
         }   
       }

    /deb
  • Deb_Allen_18's avatar
    Deb_Allen_18
    Historic F5 Account
    Oops, sorry, that first example doesn't work since the first directory is a substring. of the 2nd. Adjusted to extract the first directory name with getfield instead of using starts_with

     

     

    /d