Forum Discussion
Irule with Multiple URL's
I'm trying to figure out how to configure a simple http redirect irule, however the irule round robins 4 different URL's, does anyone know how to write this?
VIP 1.1.1.1 -----> www.abc.com www.aaa.com www.bbb.com www.ccc.com
6 Replies
- Cory_50405
Noctilucent
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] } - Freddy_Delgado_
Nimbostratus
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
Noctilucent
Is this iRule working to redirect between just two sites?
- Cory_50405
Noctilucent
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] } - hoolio
Cirrostratus
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
- Freddy_Delgado_
Nimbostratus
That worked thanks!
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com