Forum Discussion

6 Replies

  • You can use the standard HTTP to HTTPS iRule that comes pre-installed with LTM, called _sys_https_redirect. It grabs whatever host the client specifies on HTTP and redirects to HTTPS.

    when HTTP_REQUEST {
           HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
        }
    
  • I guess that would be for a redirect to https, I would need something similar to this irule but instead of just two urls, I need it to alternate between 4 urls.

     

    when RULE_INIT { set ::whichone 0 } when HTTP_REQUEST { switch $::whichone { 0 { HTTP::redirect "http://www.test.com” } 1 { HTTP::redirect "http://www.test1.com” } } set ::whichone [expr ! $::whichone]

     

    • Cory_50405's avatar
      Cory_50405
      Icon for Noctilucent rankNoctilucent
      Is this iRule working to redirect between just two sites?
  • Modified to use your four specified FQDNs:

    when RULE_INIT {
     set ::whichone 0
    } 
    
    when HTTP_REQUEST { 
     switch $::whichone { 
      0 { HTTP::redirect "http://www.abc.com” }
      1 { HTTP::redirect "http://www.aaa.com” } 
      2 { HTTP::redirect "http://www.bbb.com” }
      3 { HTTP::redirect "http://www.ccc.com” }
      }
     set ::whichone [expr ! $::whichone]
    }
    
  • Cory you have a good example, but using a global variable will disable CMP for that virtual server and it will only run on the first tmm.

    https://devcentral.f5.com/wiki/irules.cmp.ashx

    Here's an example using a psuedo random number to select between the four URLs:

     Based on https://devcentral.f5.com/wiki/iRules.ratio_load_balancing_using_rand_function.ashx
    when HTTP_REQUEST {
         Save a psuedo-random number between 0 and 1
        set rand [expr { rand() }]
        if { $rand < .25 } {
            HTTP::redirect "http://www.1.com"
        } elseif { $rand < .50 } {
            HTTP::redirect "http://www.2.com"
        } elseif { $rand < .75 } {
            HTTP::redirect "http://www.3.com"
        } else {
            HTTP::redirect "http://www.4.com"
        }
    }
    

    Aaron