iRule – Redirects

#Different Redirects ########################  302 Redirects ######################## when HTTP_REQUEST {     HTTP::redirect https://www.domain.com/ } ########################  301 Redirects ######################## when HTTP_REQUEST {     HTTP::respond Location 301 https://www.domain.com/ } ############################ IF-Conditional Redirect: ############################ # Matching a condition when HTTP_REQUEST {     if {[HTTP::host] eq “domain.com”} {        … “iRule – Redirects”

Read More

iRULE – String Usage

when HTTP_REQUEST { set URI [string tolower [HTTP::uri]] if {$URI starts_with “/m/” }{ set NEW_URI [string range [HTTP::uri] 2 end] HTTP::respond 301 Location http://www.domain.com$NEW_URI } } $ curl -Ik http://10.10.10.10/m/URI HTTP/1.0 301 Moved Permanently Location: http://www.domain.com/URI Server: BigIP Connection: Keep-Alive Content-Length: 0 Replacing set NEW_URI … “iRULE – String Usage”

Read More

F5 iRule – User Agent

when HTTP_REQUEST { set HOST [string tolower [HTTP::host]] if { ($HOST eq “domain.com” || $HOST eq “www.domain.com” ) and ([HTTP::header User-Agent] contains “Chrome/33.0.175”) and ([HTTP::header User-Agent] contains “(X11; Linux x86_64)”) } { reject } } The above iRule will enable the F5 to send a … “F5 iRule – User Agent”

Read More

F5 iRule – URI Encoded

when HTTP_REQUEST { if { [active_members [LB::server pool]] < 1 } { set STATIC_SORRY [URI::decode “%3C!DOCTYPE%20HTML%3E%0A%3Chtml%3E%0A%3Chead%3E%0A%3Cmeta%20charset%3D%22UTF-8%22%3E%0A%3Ctitle%3EOops!%20We%27ll%20be%20back%20shortly%3C%2Ftitle%3E%0A%3Cstyle%3E%0A*%20%7B%09margin%3A0%3Bpadding%3A%200%3B%7D%0Ahtml%2C%20body%7B%20height%3A100%25%3B%20color%3A%20%23333%3B%20font-family%3AHelvetica%2C%20Arial%2C%20sans-serif%3B%7D%0A.wrapper%20%7Bmax-width%3A%20960px%3Bwidth%3A100%25%3Bmargin%3A0%20auto%3Bdisplay%3Atable%3Bheight%3A100%25%3B%7D%0A.container%20%7Bdisplay%3A%20table-cell%3Bvertical-align%3A%20middle%3Btext-align%3Acenter%3B%7D%0Ah1%20%7Bfont-size%3A60px%3B%7D%0Ah2%20%7Bfont-weight%3Anormal%3Bfont-size%3A60px%3Bmargin-bottom%3A0.36em%3B%7D%0Ap%20%7Bline-height%3A1.4em%3Bmargin%3A0%200%201.3em%200%3B%7D%0A%3C%2Fstyle%3E%0A%3C%2Fhead%3E%0A%3Cbody%3E%0A%3Cdiv%20class%3D%22wrapper%22%3E%0A%3Cdiv%20class%3D%22container%22%3E%0A%3Ch1%3EOops!%3C%2Fh1%3E%0A%3Ch2%3EWe%27ll%20be%20back%20shortly.%3C%2Fh2%3E%0A%3Cp%3ESorry%20for%20the%20inconvnience%2C%20please%20try%20again%20in%20a%20few%20minutes%3C%2Fp%3E%0A%3C%2Fdiv%3E%0A%3C%2Fdiv%3E%0A%3C%2Fbody%3E%0A%3C%2Fhtml%3E”] HTTP::respond 200 content $STATIC_SORRY } } The above iRule can be utilized in order to serve a sorry page when all the pool members in the default pool (pool … “F5 iRule – URI Encoded”

Read More

iRule – Persistence Across HTTP Method

when HTTP_REQUEST { set HOST [string tolower [HTTP::host]] #Persistence is enabled for specific domain if { $HOST equals “domain.com” }{ #Persistence for GET Request if { [HTTP::method] equals “GET” } { set SESSIONID [findstr [HTTP::uri] “uuid=” 5 20] set KEY [crc32 $HOST$SESSIONID] persist hash $KEY … “iRule – Persistence Across HTTP Method”

Read More