Kenny_Van_73892
Feb 12, 2009Nimbostratus
strip away www. and redirect to https:// without cert mismatch error
I need some help to clear my mind.
I need to strip away www. from host either on port 80 or 443 and redirect to https://. For instance, if user enters http or https://www.sub.mycompany.com then it must get stripped away www. and redirects to https://sub.mycompany.com, if user enters http or https://sub.mycompany.com then it just redirects to https://sub.mycompany.com.
I came up with this, but couldn't get it to work the way I wanted and got certificate error because the host didn't match with registered SSL host as sub.mycompany.com.
if {[HTTP::host] starts_with "www." and [TCP::local_port] eq 80 or [TCP::local_port] eq 443} {
HTTP::redirect https://www.sub.mycompany.com [string range [HTTP::host] 4 end][HTTP::uri]
} elseif { [TCP::local_port] eq 80 } {
HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
}
So, how do I strip the www. away and cert won't complain mismatch?
Thanks in advance.