Reputation: 69
I'm looking to use htaccess to remove www, and force https ONLY for main domain (no subdomains). I was also hoping to avoid hard coding my domain or any of the subdomains. Here is what I am currently using, but it is forcing https for subdomains.
Thanks in advance,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^ %{REQUEST_SCHEME}://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Upvotes: 1
Views: 258
Reputation: 41219
Try this :
RewriteEngine on
RewriteCond %{REQUEST_SCHEME}#%{HTTP_HOST} ^http#(?:www\.)?(example\.com)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R]
Replace example.com with your main domain.
Upvotes: 3