htaccess force https & www. on domain & http no www on subdomain htaccess force https & www. on domain & http no www on subdomain apache apache

htaccess force https & www. on domain & http no www on subdomain


You can use:

# for main domainsRewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]RewriteCond %{HTTPS} off [OR]RewriteCond %{HTTP_HOST} !^www\. [NC]RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE]# for sub domainRewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$ [NC]RewriteCond %{HTTPS} on [OR]RewriteCond %{HTTP_HOST} ^www\. [NC]RewriteRule ^ http://sub.domain.com%{REQUEST_URI} [R=301,L,NE]

You need to test this after clearing your browser cache.