Forum Discussion
Matt_H_58911
Nimbostratus
Sep 17, 2007BIG-IP 9.1.0 Build 6.2 IRULE ** Newbie**
I've inherited this wonderful device and now need to learn how to write an irule.
Objective:
What I would like to do is match on a URL and send requests for certain portions of pages to a new server(via IP address).
For example, any request coming in for
http://www.domainname.com/cached/* or
http://www.domainname.com/assets/* or
http://www.domainname.com/art/*
is then sent to a specific destination server.
Any assistance would be very helpful
Thanks!
12 Replies
- Matt_H_58911
Nimbostratus
My first attempt at this:
when HTTP_REQUEST {
if { [HTTP::uri] ends_with "cached" } {
pool NSF
} elseif { [HTTP::uri] ends_with "assests" } {
pool NSF
} elseif { [HTTP::uri] ends_with "art" } {
pool NSF
}
}
Will this work for what I want? - dennypayne
Employee
That should work fine. If your list grows beyond 3 URLS, you will probably want to look at the matchclass functions (see the wiki) so that you can do one comparison against a list instead of a comparison for each possibility.
Also your current rule will "fall out" to the default pool defined in the virtual without a match, if you want to be more specific about that you can end with an "else" and direct that to the default pool.
Denny - dennypayne
Employee
EDIT: See this post Click here for more information about default pool selection...it is usually better to explicitly define it.
Denny - Matt_H_58911
Nimbostratus
Denny,
Thanks for the reply. The next question is how do we keep the persistence for the sessions. Here is what another tech said in regards to this.
The problem with that is the persistence that is enabled. When using that rule, any connection that makes a request to /cached/, /art/, or /assets/ will have its entire connection moved over to the NFS server, which is invalid. I was trying to find a way to disable persistence for individual requests in hopes of being able to disable persistence, send the request to the NFS server and then re-enable persistence.
Is this possible? - Matt_H_58911
Nimbostratus
Further clarification on the above is that the code will drop you to the new server (NFS) or the NFS pool but then we need to be able to traverse back to the default web pool. How do I add at the end of the code that the following request after it gets what is needed from the NFS pool to go back to the web pool? - Deb_Allen_18Historic F5 AccountHi Matt -
This rule does the same thing as the if/else version, and adds a default pool selection for any non-matching request:
You'll also need to apply a OneConnect profile to ensure that multiple requests on the same connections are not routed to the first pool chosen for that connection.when HTTP_REQUEST { switch -glob [HTTP::uri] { *cached - *assets - *art {pool NSF} default {pool web} } }
HTH
/deb - Matt_H_58911
Nimbostratus
Deb,
Thanks for the post but I'm not sure I follow the OneConnect profile. How does this work? - Matt_H_58911
Nimbostratus
I've looked at implementing the OneConnect profile and it appears to be out of my league. Looking at the ONECONNECT::detach [enable | disable ]
I suppose when I meet the criteria in the above code I want to detach
when HTTP_REQUEST {
switch -glob [HTTP::uri] { ONECONNECT::detach enable
*cached -
*assets -
*art {pool NSF}
default {pool web}
}
}
My question is do I need to add a ONECONNECT::reuse enable? - Matt_H_58911
Nimbostratus
Will the above code work? I'm trying to test this and it appears to still be using the NFS pool. - Deb_Allen_18Historic F5 AccountOh, sorry for the confusion. I should have been clearer.
You can either create a custom oneconnect profile (Virtual Servers / Profiles / Other / OneConnect) or apply the default oneconnect profile to the virtual server itself by selecting the desired profile for the "OneConnect Profile" setting. The profile will then apply to all connections passing through it. Leave "OneConnect Transformations" enabled in the applied http profile. (It is enabled by default.)
If you want instead to go the detach route, the command you want is actually "LB::detach", and you'd put it immediately above the pool command. But using the profile as described above is simpler & more efficient, so I'd go that route.
HTH
/deb
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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