tom's blog logo

HTTP Redirect with an iRULE on Big-IP F5

Post by Thomas Weaver on April 3, 2011 11:11 am

Big-IP F5 Local Traffic Manager load balancers are extremely poweful devices. One of the nicest features on the F5′s are the iRRules. iRules are small bit of code that the user can specify which can edit the HTTP Headers or any of the traffic going through the F5 to a specific Virtual Server.

This can be extremely powerful for example in the this post I will give an example of how you can redirect a website using an iRule so that someone going to test.test.com will be redirected to www.test.com.

For this to work the easiest way is to set in DNS the same ip for test.test.com and www.test.com.

The best way to edit iRules is to use the iRule editor which will check your syntax and actually upload it to your F5 if you wish. You can download the iRule editor from here:

http://devcentral.f5.com/Community/GroupDetails/tabid/1082223/asg/1/aft/1172053/showtab/groupforums/Default.aspx

So lets create an iRule to redirect HTTP traffic. Below is an example of this:

when HTTP_REQUEST {
	if{ [HTTP::host] contains "test.test.com"} {
		HTTP::redirect http://www.test.com[HTTP::uri]
	}
}

So when the F5 receives a HTTP_REQUEST check to see if the HTTP::host in the HTML header contains test.test.com i.e. if the client has request a page for test.test.com. Then redirect the client to www.test.com and to the same page they requested originally. The HTTP::uri at the end is important because it will redirect the user exactly to the page they have requested which is important if you have suddenly changed your URL for people have bookmarked the old one.

One thing to note is that if you want to redirect HTTPS traffic you would need a certificate that covers both domain names otherwise you will get a certificate error. This is because the URL is encrypted so the F5 cannot see it so it doesnt redirect until the session has been set up which is too late as the client has already received the certificate.

As you can see iRules can be extremely powerful but also very simple to use above is only a very basic iRule but a very effective one.

Post a Comment

Your email address will not be published. Required fields are marked *


*