To limit loop, you can apply the following irule to both http and https VS:
when HTTP_REQUEST {
set redirect 0
set host [HTTP::host]
set uri [HTTP::uri]
set domain "company.com"
if { !($host contains ".")} {
If domain is not set, append domain to host variable and force redirect
set HostName $host
set host "$host.$domain"
set redirect 1
} else {
set HostName [getfield $host "." 1 ]
}
if { $uri equals "/" } {
set newuri [class lookup ${HostName} REDIRECTS]
if { !(${newuri} eq "/") && (${newuri} ne "") } {
set redirect 1
set uri $newuri
unset newuri
}
}
if {$redirect} {
HTTP::respond 301 noserver Location "https://$host${uri}" Connection Close
}
}