Forum Discussion

Waynew_97737's avatar
Waynew_97737
Icon for Nimbostratus rankNimbostratus
Mar 11, 2009

How to do http redirect

We are presently in the process of migrating all stuff from CSS's to F5s. Presently, we have a CSS with a configuration that does something like this

 

 

User goes to https://www.acme.com

 

user gets redirected to https://www.acme1.com or https://www.acme2.com

 

 

Do I need to do this using irules, or is there another way to do this?

4 Replies

  • Clarification: you want 50% of the requests for / to get redirected to acme1 and the other 50% redirected to acme2 ?

     

     

  • ^^ Yes, if there is a way to weight them as well (say send 30% of the traffic to one acme1 and 70% to acme2), I'd like to know.
  • Do you really want to send the client a redirect? This will update the address bar in the browser and potentially prevent LTM from load balancing the requests if acme1.com and acme2.com don't resolve to a VIP address.

    If so, here is a rough example of this ratio load balancing. I'm sure there are other ways to do it, but this is one method.

    Aaron

     
     when RULE_INIT { 
      
         Log debug messages (to /var/log/ltm)?  0 = no, 1 = yes. 
        set ::site_router_debug 0 
      
         Percentage of new requests to send to new site (valid values: integers from 0 - 10; with 1 being 10%, 5 being 50%, 10 being 100%) 
        set ::site1_ratio {5} 
      
         Initialise a counter for ratio load balancing between the legacy and new site. 
         (this value shouldn't be changed) 
        set ::counter 0 
     } 
     when HTTP_REQUEST { 
      
           Send first X out of 10 requests to the new site.  Then send next 10 minus X requests to the legacy site. 
        if {$::counter < $::site1_ratio}{ 
      
           if {$::site_router_debug}{log local0. "Counter < max: $::counter < $::site1_ratio.  Selected site1."} 
      
            Redirect to a URL. Set headers to prevent caching of response. 
           HTTP::respond 302 \ 
              "Location" "https://site1" \ 
              "Connection" "Close" \ 
              "Cache-Control" "no-cache" \ 
              "Pragma" "no-cache" 
      
        } else { 
      
           if {$::site_router_debug}{log local0. "Counter > max: $::counter > $::site1_ratio.  Selected site2."} 
       
            Redirect to a URL. Set headers to prevent caching of response. 
           HTTP::respond 302 \ 
              "Location" "https://site2" \ 
              "Connection" "Close" \ 
              "Cache-Control" "no-cache" \ 
              "Pragma" "no-cache" 
        } 
      
         Increment the counter for ratio load balancing 
        incr ::counter 
      
         If counter is over the max, reset it to 0 
        if {$::counter > 10}{ 
           set ::counter 0 
           if {$::site_router_debug}{log local0. "Counter: $::counter, resetting to 0"} 
        } 
     }