Forum Discussion
2 actions in the same rule: redirect + load balance
Hi all,
I need to make an iRule whose behaviour is:
1.- When the web starts with "/a/b" redirect to "/b" AND balance to the pool POOL_x.x.x.x_8090 2.- When the web starts with "/a/" redirect to "/" AND balance to the pool POOL x.x.x.x_8090
I managed to do it with 2 irules:
First: redirect
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/a/b" } { HTTP::redirect "http://[HTTP::host]/b" } elseif { [HTTP::uri] starts_with "/a" } { HTTP::redirect "http://[HTTP::host]/" } }
Second: Balance
when HTTP_REQUEST { set myURL [HTTP::uri] if { $myURL starts_with "/" } { pool POOL_x.x.x.x_8090 } elseif { $myURL starts_with "/b } { pool POOL_x.x.x.x_8090 } }
But I must consolidate in the same iRule,
Any ideas?
Regards
6 Replies
- PeteWhite
Employee
You can also just skip the redirect and instead change the URL and loadbalance HTTP::path
- COMMS-CORE_1795
Nimbostratus
Hi Pete,
I´m new in iRules, Can you be more especific? With an example,
Thanks in advanced
- PeteWhite
Employee
How about this:
when HTTP_REQUEST { if { [HTTP::path] starts_with "/a/b" } { pool POOL_ABC set HTTP::path "/" } elseif { [HTTP::path] starts_with "/b } { pool POOL_XYZ set HTTP::path "/" } } - COMMS-CORE_1795
Nimbostratus
Pete,
Is possible maintain the redirect and alsa do the balance?
- Charles_Lamb
Nimbostratus
By changing the path and selecting which pool to go to you are negating the need for a redirect.
You would only want to use the redirect if you needed to send a traffic to a completely different host that is not hosted on this F5.
Hi Comms-Core,
you can chain as many conditions in a single
command by using[if]
orelseif
conditions. The most restictive conditions are evaluated first followed by the least most restictive conditions.elseBased on your provided requirements, the
command would look like this.[if]when HTTP_REQUEST { Format the URI tolower to negate the CASE while comparing the requested URIs set low_uri [string tolower [HTTP::uri]] Evalute the contition step-by-step. Starting with the most restrictive condition... if { $low_uri starts_with "/a/b" } then { HTTP::redirect "http://[HTTP::host]/b" } elseif { $low_uri starts_with "/a" } then { HTTP::redirect "http://[HTTP::host]/" } elseif { $low_uri starts_with "/b" } then { pool POOL_1.1.1.1_8090 } else { The else condition will catch everything else (e.g. /*) pool POOL_2.2.2.2_8090 } }Cheers, Kai
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