Forum Discussion
JRahm
Nov 13, 2015Admin
you need to specify the action for both conditions. string tolower is not necessary on the host as it is case insensitive according to the RFC. This should work for you:
when HTTP_REQUEST {
if { [llength [split [HTTP::host] "."]] < 3 } {
HTTP::redirect http://www.[HTTP::host][HTTP::uri]
}
}
This splits the host by the period. If the list is only two items long, then it doesn't have the www before domain.com and redirects.
Example:
% set x "domain.com"
domain.com
% set y "www.domain.com"
www.domain.com
% if { [llength [split $x "."]] < 3 } { puts "prepend" } else { puts "all good" }
prepend
% if { [llength [split $y "."]] < 3 } { puts "prepend" } else { puts "all good" }
all good