What could you do with your code in 20 Lines or Less? That's the question I ask (sometimes?) every week 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'm digging through my list of cool threads from the past month or so and picking out a few that I think are interesting. More to follow, but we're starting with a cool little geolocation redirection rule that will allow you to direct people from different countries (or states) to different URLs, a nifty domain blocking rule to help thwart would be defamers with derogatory subdomains, and some math in iRules...because well, George is a math geek, and so am I. This is a heck of a variety this week, so buckle up for some fun code.


iRule Redirect via Geolocation


This example shows off just how easy it is to do geolocation look ups in iRules. The user was looking for a way to redirect people to different URLs based on their geographical location. At first it was thought that a CDN would make it necessary to read the XFF header, but it turned out not to be the case. Regardless, this same idea would work either way, assuming you can trust the XFF header (which...you often can't).