This is untested.
Also see this page:
https://devcentral.f5.com/wiki/iRules.HTTP__respond.ashx
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/cookies/set" } {
set fmt "%d %b %Y %H:%M:%S %Z"
set expiry [clock format [clock seconds] -format $fmt]
set domain ".[getfield [HTTP::host] . 2].[getfield [HTTP::host] . 3]"
set testrouter [string trim [URI::path [HTTP::uri] 3] "/"]
HTTP::respond 302 -version 1.1 Set-Cookie "TESTROUTER=$testrouter; path=/; expires=$expiry; domain=$domain" Location "http://www.123.com"
}
}