Reputation: 21
There are many similar solutions on Stack Overflow such as htaccess http to https with www. Without redirecting sub domain.
What I need, however, is:
I am running a WordPress Multisite website and have no wildcard SSL.
I am using the following at the moment:
Non-WWW
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} www.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Non-WWW and Non-HTTPS Sub-Domains
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !=subdomain1.main.com
RewriteCond %{HTTP_HOST} !=subdomain2.main.com
RewriteCond %{HTTP_HOST} !=subdomain3.main.com
RewriteCond %{HTTP_HOST} !=subdomain4.main.com
SSL
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Upvotes: 2
Views: 145
Reputation: 5748
Is this what you want?
RewriteEngine On
RewriteBase /
# www is redirected to base domain
RewriteCond %{HTTP_HOST} ^www\.([^\.]+\.[^\.]+)$
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]
# base domain should use HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^[^\.]+\.[^\.]+$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
# other domain should use HTTP
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^[^\.]+\.[^\.]+$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [L,R=301]
Upvotes: 1