I want to force users to use https on my site. I use this piece of code in the htaccess:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R,L]
It all works fine, expect that it forces https on subdomains too (eg. subdomain.mysite.com is forced to https as well). I want to force only my domain to https, and not any of the subdomains.
How to do this?
Here's what should work:
RewriteEngine On
RewriteCond %{HTTP_HOST} (www\.){0,1}mydomain\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://www.mysite.com/$1 [R,L]
Please tell me if it did the trick ;)
来源:https://stackoverflow.com/questions/8194475/htaccess-mod-rewrite-force-using-https-but-not-on-subdomains