Forum Discussion

Frank_30524's avatar
Frank_30524
Icon for Nimbostratus rankNimbostratus
Apr 16, 2009

convert irule from 9.x to 4.x

I am relatively new to 4.x and need help converting a redirect irule.

 

Here is it in version 9.x.

 

 

when HTTP_REQUEST {

 

if { [HTTP::uri] eq "/" and [HTTP::host] eq "www.abc.abc.com" } {

 

HTTP::redirect "http://www.abc.abc.com:8000/bla/bla"

 

} else {

 

HTTP::redirect "https://[HTTP::host][HTTP::uri]"

 

use pool abc-pool

 

}

 

}

 

 

any help would be appreciated.

 

 

Thanks in advanced.

3 Replies

  • You can rewrite it in the following ways:

      
     when HTTP_REQUEST {   
     if { ([HTTP::uri] eq "/") and ([HTTP::host] eq "www.abc.abc.com") } {   
     HTTP::redirect "http://www.abc.abc.com:8000/bla/bla"   
     } else {   
     HTTP::redirect "https://[HTTP::host][HTTP::uri]"   
     pool abc-pool  
     }   
     }   
     

    or

      
     when HTTP_REQUEST {   
     if { ([HTTP::uri] eq "/") and ([string tolower [HTTP::host]] eq "www.abc.abc.com") } {   
     HTTP::redirect "http://www.abc.abc.com:8000/bla/bla"   
     } else {   
     HTTP::redirect "https://[HTTP::host][HTTP::uri]"   
     pool abc-pool  
     }   
     }   
     

    or

      
     when HTTP_REQUEST {   
     if { ([HTTP::host] eq "www.abc.abc.com") and ([HTTP::uri] eq "/") } {   
     HTTP::redirect "http://www.abc.abc.com:8000/bla/bla"   
     } else {   
     HTTP::redirect "https://[HTTP::host][HTTP::uri]"   
     pool abc-pool  
     }   
     }   
     

    Hope this helps

    CB
  • Thanks,

     

    I've been playing with this and keep getting this error:

     

     

    Error 331835 -- Rule string to tree failed. - syntax error at 'when'

     

    line 1: when HTTP_REQUEST {

     

     

    Can't seem to get past it.

     

     

    Thanks
  • Those are 9.x formatted iRules, so they won't work in a 4.x unit. Also, for the else clause, do you want to redirect the client or select the pool? They are two distinct actions which can't both be done.

    Here is a rough start for a 4.x version of the iRule. I don't have ready access to a 4.x unit, so I can't confirm the syntax is perfect.

     
     if (http_uri == "/" and http_host == "www.abc.abc.com" ) { 
        redirect_to "http://www.abc.abc.com:8000/bla/bla" 
     } else { 
        redirect_to "https://[HTTP::host][HTTP::uri]" 
         OR  
        use pool abc-pool 
     } 
      
     

    Aaron