simple iRule

Very new to iRules.

How would i redirect http://domain.com to http://www.domain.com

Try this:

when HTTP_REQUEST { 
   if { [HTTP::host] equals [domain [HTTP::host] 2] } { 
     HTTP::redirect www.[HTTP::host] 
   } 
 }