Forum Discussion
Help on a irule
Hello Everybody, i'm a newbie in irules and need some help in order to change an old irule to something simple and i'm don't know if i'm doing it right.
Original Irule ( when i put up on V11 i got a few error messages)
when HTTP_REQUEST { set url_var text([HTTP::host])
if { $url_var contains "sitea.test.com" } { HTTP::redirect "sitec.test.com/index" } if { $url_var contains "siteb.test.com" } { HTTP::redirect "http://test3.test.com/test" }
if { $url_var contains "sitec.test.com" } { HTTP::redirect "http://test3.test.com/login" } } }
I've tried to use the following irule but i'm getting errors anyway.
when HTTP_REQUEST { if {[string tolower [HTTP::host]] contains "sitea.test.com" { HTTP::redirect "http://sitec.test.com/index"} if {[string tolower [HTTP::host]] contains "siteb.test.com" { HTTP::redirect "http://test3.test.com/test"} if {[string tolower [HTTP::host]] contains "sitec.test.com" { HTTP::redirect "http://test3.test.com/login"}
Am i doing something wrong? Can someone point out the best way to do these redirects?
Thanks!
5 Replies
- Kevin_Davies_40
Nacreous
when HTTP_REQUEST { if { [class match [string tolower [HTTP::host]] contains mysites] } { HTTP::redirect [class match -value [string tolower [HTTP::host]] contains mysites] } }With string class "myclass" as follows
Key Value sitea.test.com http://sitec.test.com/index siteb.test.com http://test3.test.com/test sitec.test.com http://test3.test.com/login- Kevin_Davies_40
Nacreous
This gives you a simple iRule using data classes which means you can remove or add sites as you please and the iRule will automatically use them. The data class is always first match. - Amanda_68359
Nimbostratus
Thanks for the tip! I will test it right away!
- ltwagnonRet. Employee
Hi Amanda...thanks for the question! Are you using v11.4+ or are you on an older version (11.3 or older)? One reason I ask is that you can do these redirects using an HTTP Class profile (v11.3) or with a policy using the new Centralized Policy Matching (CPM) in version 11.4 and newer. You very likely won't even need an iRule! I can point you in the right direction based on the version you are using.
Thanks! John
- James_Deucker_2Historic F5 Account
Also, you can achieve all of this with HTTP Class profiles (up to v11.3) or HTTP Policies from v11.4+
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