I have own the example.tld
.
I want to force SSL and https for root-domain
and all of its subdomains
.
I have used below code in .htaccess
file of root-domain:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.tld$ [NC]
RewriteRule ^(.*)$ https://www.example.tld/$1 [L,R=301]
It looks work perfectly for root-domain.
But, for subdomains like as blog.example.tld
, I have used different suggestions, such as:
RewriteCond %{HTTP_HOST} ^blog\.example.\tld$ [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
But, none of them works properly, and they will redirect to ssl www version of root-domain
, instead of ssl www version of subdomain
.
What should I do?