What could you do with your code in 20 Lines or Less? That's the question I like to ask for the DevCentral community, and every week I go looking to find cool new examples that show just how flexible and powerful iRules can be without getting in over your head.

This week I've dug into the forums and found a few examples of some super simple ways that iRules can just plain make your life easier. They aren't complex, crazy examples like I sometimes lean towards, and I think that's a good thing. These are approachable, real world solutions that you can snag, implement, and check item #192873 off of your to-do list in a matter of minutes. iRules are capable of such a vast array of things, and I've been using them for so long now, that I tend to lose focus on some of the simpler things. I've grabbed a few that I think are great examples of those principle concepts, and here they are for your perusal.

 

OWA & HTTPS Redirect

https://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/50/aft/2161815/showtab/groupforums/Default.aspx

The concept here is really simple - the user (pjcampbell) wants to write a redirect that takes users from HTTP to HTTPS, while simultaneously pointing them at the "/owa" URI when someone requests the webmail cname of their domain. That sounds pretty logical and straight forward, right? Well, the iRule is. As you can see below this is something super simple. Hooley even went so far as to make it redirect all requests to HTTPS, assuming that security is a good thing (pro tip: it is). That being said, there's something that came up that I didn't expect to see in this discussion - a port 80 VIP. Turns out that pjcampbell only had a 443 VIP. Well, when I stop and think about it, I can see why that might be the case. They want things to run on port 443, so why wouldn't they create a 443 VIP? The thing is, for the iRule to do it's magic in the redirection from HTTP to HTTPS, it has to listen on HTTP. So a port 80 VIP is where this kind of iRule should live if it's going to be doing 80->443 translation. They might want a version that just does the straight URI redirect (no HTTP->HTTPS change) on the port 443 VIP as well, but that's just a safety of sorts to be sure people aren't typing in the HTTPS link manually or something.

The iRule itself is simple as can be.

#Colin