Forum Discussion

habib_Khan's avatar
habib_Khan
Icon for Nimbostratus rankNimbostratus
Jan 12, 2016

Irule is not working. KIndly help.

I have a vip with below are the 2 irules confirgured for redirecting to different pools. The irules are not working when url is tried with htt://abc.com/socket.io. Please correct if irules.

 

irule 1:

 

when HTTP_REQUEST { set hostname [string tolower [HTTP::host]] set tops_uri [string tolower [HTTP::uri]] if { $hostname contains "topssit" } { pool topssit-http } if { ($hostname contains "topsstg") && ($tops_uri starts_with "/socket.io")} { pool topsstg-socket-pool } if { $hostname contains "topsstg" } { pool topsstg-pool } if { $hostname contains "topstrg" } { pool topstrg-pool } if { $hostname contains "topsfat" } { pool topsfat-prod-pool } }

 

Irule 2 called in vip Name:Tops url redirect

 

when HTTP_REQUEST { if {([HTTP::uri] equals "/") || ([HTTP::uri] equals "/tops")}{ HTTP::redirect "http://[HTTP::host]/tops/" } }

 

2 Replies

  • Hello Habib,

     

    Could you please wrap your iRule inside a code-block for better visibility?

     

    Code
    Code
    ...
  • Hi Habib,

    I've optimized the iRules for you. Instead of chaining multiple

    [if { $condition} then { action }]
    commands, you should use a single
    [if { $condition} then { action } elseif { $condition2 } then { action }]
    command. Using the later would stop comparsion after the first match and would save some CPU cycles.

    In addition I've integrated the abc.com requirement for your. Please review and tweak the desired actions for this URL as needed...

    iRule1:

    when HTTP_REQUEST { 
        set low_hostname [string tolower [HTTP::host]] 
        set low_uri [string tolower [HTTP::uri]]
        if { $low_hostname contains "topssit" } then { 
            pool topssit-http 
        } elseif { ( $low_hostname contains "topsstg" ) and ( $low_uri starts_with "/socket.io" ) } then {
            pool topsstg-socket-pool
        } elseif { ( $low_hostname equals "abc.com" ) and ( $low_uri starts_with "/socket.io" ) } then {
            pool abc_com-socket-pool
        } elseif { $low_hostname contains "topsstg" } then { 
            pool topsstg-pool 
        } elseif { $low_hostname contains "topstrg" } then { 
            pool topstrg-pool 
        } elseif { $low_hostname contains "topsfat" } then { 
            pool topsfat-prod-pool 
        } else {
             Rely on virtual server configuration
        }
    }
    

    iRule2:

    when HTTP_REQUEST { 
        if { ( [HTTP::uri] equals "/" ) or ( [HTTP::uri] equals "/tops" ) } then { 
            HTTP::redirect "http://[HTTP::host]/tops/" 
        }
    }
    

    Cheers, Kai