14 November 2012

Handy simple F5 redirect iRules

iRules are great and extremely powerful. If however you just want to dip your toes in to do a few basic redirects it can be a bit confusing.

Here are a few very basic iRules that can be used to do "the basics"

Add your domain suffix to a naked domain name

Converts: http://hostname to http://hostname.mydomain.com


when HTTP_REQUEST {
 if { not ([HTTP::host] contains ".mydomain.com")}{
 HTTP::redirect "http://[HTTP::host].mydomain.com[HTTP::uri]"
 }
 }

Add domain suffix and change HTTP to HTTPS

Converts: http://hostname to https://hostname.mydomain.com


when HTTP_REQUEST {
 if { not ([HTTP::host] contains ".mydomain.com")}{
 HTTP::redirect "http://[HTTP::host].mydomain.com[HTTP::uri]"
 }
 }

Change HTTP to HTTPS

Converts: http://any/any to https://any/any


when HTTP_REQUEST {
       HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
    }

Specify a default landing page


Converts: http://mysite/ to http://mysite/default/defaultpage.aspx

when HTTP_REQUEST {
       HTTP::redirect http://[getfield [HTTP::host] ":" 1]/default/defaultpage.aspx
    }



Custom 404 response

Converts: https://myside.mydomain.com/broken-link to https://mysite.mydomain/sorrypage.apsx


when HTTP_RESPONSE {
if { [HTTP::status] == 404} {
HTTP::redirect "https://mysite.mydomain/sorrypage.apsx"
}
}


Those are just the very basics you would probably be looking for to be able to do in the management GUI


Some more info:
https://devcentral.f5.com/wiki/iRules.HomePage.ashx
http://fir3net.com/Big-IP-F5-LTM/irule-examples.html




No comments:

Post a Comment