Forum Discussion
Danielseyoum
Altostratus
Jan 23, 2008Calling another iRule from with in an iRule
I am inspecting the header for cookie and would like to direct the request accordingly. If cookie is not there the landing page will issue the cookie according to the user's choice of department. By the way all the URLs resolve to the same VIP.
The challenge I am facing is to make sure the URIs are valid for the corresponding URL. Meaning I have to allow certain URI only. I have an other iRule using switch. Can I call another iRule for the matching cookie i.e. call HR_iRule for HR cookie? If so how?
Cookie_iRule
when HTTP_REQUEST {
switch [HTTP::cookie Department] {
"SALES" { HTTP::redirect "http://sales.abc.com"}
"HR" { HTTP::redirect "http://hr.abc.com"}
"IT" { HTTP::redirect "http://it.abc.com"}
default{HTTP::redirect "http://www.abc.com}
}
HR_iRule
when HTTP_REQUEST {
switch [string tolower [getfield [HTTP::uri] "/" 2]]
"benefits"{ HTTP::redirect "http://hr.abc.com/portal/Benefits"}
"ethics"{ HTTP::redirect "http://hr.abc.com/portal/Ethics"}
default{HTTP::redirect "http://hr.abc.com/portal}
}
4 Replies
- hoolio
Cirrostratus
You can't call one rule from another, but if you add both rules to the VIP, they'll both be evaluated. One thing to be aware of is that you don't want to try to redirect a request multiple times, so make sure that only one of the switch conditions will be true per request.
You could also consider combining the two rules into one and then add logic to ensure only one condition will be true. If you want to stop further processing of the event you're in, you can use the return command.
I'm not too clear on what relationship, if any, there is between the cookie and the URI or I'd give you an example.
Aaron - Danielseyoum
Altostratus
when the cookie is of HR, I want the HR_iRule to be processed - hoolio
Cirrostratus
Does the HR site, hr.abc.com, resolve to the VIP which you're going to use the cookie rule logic on? If so, once the Department cookie is set, I would expect the client to present the Department cookie on every request and get constantly redirected to hr.abc.com.
Can you provide more detail on the overall flow you're trying to use in the rule? When do you want clients to be redirected, and when do you want them to be sent to a/the pool?
Aaron - Danielseyoum
Altostratus
All the sites resolve to the same VIP. The link that I am looking for is between once the cookie has been identified and start processing the iRule corresponding to the site. Per your recommendation combining the rules I have the following:
when HTTP_REQUEST {
if {[HTTP::cookie Department] == "HR" }{
switch [string tolower [getfield [HTTP::uri] "/" 2]]
"benefits" { HTTP::redirect "http://hr.abc.com/portal/Benefits"}
"ethics" { HTTP::redirect "http://hr.abc.com/portal/Ethics"}
"portal" {pool pool_hr}
default {HTTP::redirect "http://hr.abc.com/portal}
}
elseif {[HTTP::cookie Department] == "IT" }{
switch [string tolower [getfield [HTTP::uri] "/" 2]]
"dc" { HTTP::redirect "http://it.abc.com/it/datacenter"}
"db" { HTTP::redirect "http://it.abc.com/it/database"}
"it" {pool pool_it}
default {HTTP::redirect "http://it.abc.com/it}
}
else {
you will be directed to the landing page to choose department
HTTP::redirect "http://www.abc.com"
}
}
Thanks for the follow up.....
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects