2

I'm trying to write rules in my .htaccess file to default to HTTPS:// with my www.mainsite.com in my Wordpress MU network. For all other subdomains, is it possible to add a wildcard *.mainsite.com rule to treat newly created sites as HTTP only?

Here is my current .htaccess file.

RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^mainsite\.com
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

Alternatively, is it just as easy to declare specific subdomains to be treated as HTTPS and/or HTTP?

Thanks for the help.

Tom Geoco
  • 815
  • 3
  • 9
  • 20

1 Answers1

3

To force SSL on only mainsite.com and www.mainsite.com

RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(www\.)?mainsite\.com
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

To add a new subdomain to your "force SSL" list

RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^((www|subdomain)\.)?mainsite\.com
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

All other sub domains would use http by default.

Ravi K Thapliyal
  • 51,095
  • 9
  • 76
  • 89
  • Thanks! In case anyone is wondering the difference between HTTP_HOST and SERVER_NAME, I found the answer here: http://stackoverflow.com/questions/2297403/http-host-vs-server-name – Tom Geoco May 15 '13 at 23:19