.htaccess Redirecting to HTTPS Excluding Subdomain

I would like to redirect all non-https requests to https except subdomain requests. for instance

http://example.com/  =>  https://example.com/
http://example.com/page  =>  https://example.com/page

But

http://m.example.com/  REMAINS  http://m.example.com/

This is what I have in my .htaccess, which redirects all requests (including sub-domians):

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

I know that I need to add a condition before the RewriteRule, but I'm completely unsure of the syntax.

+5
source share
1 answer

Add more RewriteCondbefore RewriteRule:

RewriteCond %{HTTP_HOST} !=m.example.com
+12
source

All Articles