Q:

Redirect http to https (excluding sub domain)

I have installed ssl on my site and my ssl license only work on base domain (not on sub domains)
i use following code in .htaccess file to redirect all http call to https. But the problem is it also redirect subdomain to my base doamin.
for example www.sub.mydomain.com redirecs to https://www.mydomain.com :(
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]

but what i want, redirect only base domain call to https not interfere sub domains :(

A:

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} www.mydomain.com
RewriteRule (.*)  https://www.mydomain.com/$1 [R=301,L]

I think the rule could be just
RewriteRule (.*)  https://www.mydomain.com$1 [R=301,L]

leaving out the extra slash, which should be included in the rule match.  But I always forget whether that works or not.

