Forum Discussion
Aug 02, 2013
sample irule for redirect / rewrite
BIG-IP VE (Virtual Edition) v10.2.4 ( build 577.0 )
Could someone please provide or point me to an irule that performs redirects / rewrites , including the match class and associated data-file. ...
Kevin_Stewart
Employee
Aug 02, 2013I'll assume that this is for incoming HTTP requests and that you're running at least BIG-IP version 10 or higher. The old find/matchclass commands have been deprecated. Also, for simplicity sake I'll assume you want an "internal" data group.
1. Create a data group. In the management GUI, go to iRules and then the Data Group tab. Create a data group of type String and start entering values. The first block is the "key" and the second block is the corresponding "value". So for example, let's say you want to do a simple redirect based on the incoming URI. Here's what the data group might look like:
A sample data group called "my_test_datagroup":
"/foo" := "foo.example.com"
"/bar" := "bar.example.com"
"/test" := "blah.example.com"
2. With the data group built, you're iRule might look something like this:
when HTTP_REQUEST {
if { [class match [string tolower [HTTP::uri]] starts_with my_test_datagroup] } {
HTTP::redirect "http://[class match -value [string tolower [HTTP::uri]] starts_with my_test_datagroup]"
}
}
Using the above iRule, if a user makes an initial request to, for example, "http://www.example.com/foo", he'll get an immediate redirect to "http://foo.example.com". The first class match command checks to see if the key (in this case the requested URI) is in the data group (URI starts_with "/foo"). The operator could be anything from "starts_with", "ends_with", "contains", "equals", and others encompassing any number of conditions. Also notice that the data group does not have to be in quotes. The second class match command then takes the value from the record that contains the matching key and inserts that into the redirect string ("foo.example.com").
This is obviously an over simplistic example because I don't know your exact requirements. Take a look at the class command wiki page for more detailed information on what's possible.
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