Forum Discussion

David_X_20743's avatar
David_X_20743
Icon for Nimbostratus rankNimbostratus
Jul 24, 2008

HTTP URI redirect

Hi

 

 

I am not sure if the following http uri redirect is possible or not.

 

Please give me a hint. Thanks

 

 

when the client request

 

 

http://test.com/test.html

 

 

The F5 will check the URI for test.html,

 

 

If matching, then rediect to

 

 

http://test.com/test1.html

 

http://test.com/test2.html

 

http://test.com/test3.html

 

 

with round robin Method.

 

 

Really confused here. If customers were asking for direct traffic to different pool, things will be lot easier for me. Do not know how to direct the traffic to three URI with round robin, please help. Thanks
  • hoolio's avatar
    hoolio
    Icon for Cirrostratus rankCirrostratus
    Something like this?

      
      when RULE_INIT {  
        
          Initialize a global counter  
         set ::redirect_counter 1  
      }  
      when HTTP_REQUEST {  
        
          Check if URI is /test.html  
         if {[HTTP::uri] eq "/test.html"}{  
        
             Redirect client according to the counter value  
            HTTP::redirect "http://[HTTP::host]/test${::redirect_counter}"  
        
             Increment the counter  
            incr ::redirect_counter  
        
             Reset the counter if it's over the limit  
            if {$::redirect_counter > 3}{  
               set ::redirect_counter 1  
            }  
         }  
      }  
      

    If the URI's don't literally ending with a number, you could use something like this:

      
      when RULE_INIT {  
        
          Initialize a global counter  
         set ::redirect_counter 1  
      }  
      when HTTP_REQUEST {  
        
          Check if URI is /test.html  
         if {[HTTP::uri] eq "/test.html"}{  
        
             Redirect client according to the counter value  
            switch $::redirect_counter {  
               1 {  
                  HTTP::redirect "http://[HTTP::host]/testUrlOne"  
               }  
               2 {  
                  HTTP::redirect "http://[HTTP::host]/testUrlTwo"  
               }  
               3 {  
                  HTTP::redirect "http://[HTTP::host]/testUrlThree"  
               }  
            }  
             Increment the counter  
            incr ::redirect_counter  
        
             Reset the counter if it's over the limit  
            if {$::redirect_counter > 3}{  
               set ::redirect_counter 1  
            }  
         }  
      }  
      

    Aaron