1

I have a server with a main domain, and several subdomains. There is independent wordpress sites/installs on each of the subdomains, and also one on the main domain. (I know about multisite, but they're all independent clients so I didn't want mixed databases).

All I want is for all of them to use HTTPS in the easiest way possible (I continue creating subsites for new clients). Usually I use the plugin "Really Simple SSL", and it works, but it doesn't seem to support subdomains in this way.

Right now I have my main domain with the plugin installed, with HTTPS fully working all good. It has this htaccess:

# BEGIN rlrssslReallySimpleSSL rsssl_version[3.2.6]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# END rlrssslReallySimpleSSL
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>    
# END WordPress

If I install the plugin and try to use it in the subsite it tried adding this code (but it automatically fails and it doesn't insert it):

# BEGIN rlrssslReallySimpleSSL rsssl_version[3.2.9]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
# END rlrssslReallySimpleSSL

To my little htaccess understanding, it fails because that is made for a main domain. My subdomain right now is being detected as non-secure.

I would like to know what should I modify to make subdomains work. It would be ideal if I could do the mod on the main htaccess, so the change works for any subdomain created and future ones by default. If not, I will need to do it on each htaccess of each subfolder (if that's the case, it's good too).

I don't want www redirections of any kind. None.

  • Can you include the file system structure. Where the subdomains and main domain point to in relation to each other and where the respective .htaccess files are located. Thanks. – MrWhite Feb 5 at 14:19
  • To confirm... HTTPS is enabled for the subdomains? – MrWhite Feb 6 at 23:29
0

...on each htaccess of each subfolder

By the sounds of it, your subdomains point to subdirectories off the main domain's document root. Bear in mind that in this scenario the root .htaccess file can influence the config of the subdomains. This can be good and bad. Although having an entirely separate WordPress install in the root is probably not recommended.

The HTTP to HTTPS redirect directives as stated should work just fine if used in the subdomain's .htaccess file.

If I install the plugin and try to use it in the subsite it tried adding this code (but it automatically fails and it doesn't insert it)
:
To my little htaccess understanding, it fails because that is made for a main domain.

It would seem to fail because those directives are "not inserted" in the subdomain's .htaccess file?! (A file permissions/owner issue perhaps?) Otherwise, there is nothing wrong with those directives, given the information in the question.

Have you tried manually adding those directives to the top of the subdomain's .htaccess file?

It would be ideal if I could do the mod on the main htaccess, so the change works for any subdomain created and future ones by default.

This is possible, however, since you have another "separate" WordPress installation in the root (parent directory) then there are going to be additional conflicts*1 that need to be resolved, so I would not necessarily recommend going this route.

*1 For instance, the WordPress front-controller in the root .htaccess file would need to either be modified to work for all subdomains or bypassed altogether.


However, if you only had WordPress installations in subdomains/subdirectories then it would be relatively trivial to have a master .htaccess file in the main domain's root that controlled such things as HTTP to HTTPS redirection etc. Apache 2.4.8+ would be required.

To have a common HTTP to HTTPS redirect in the parent/root .htaccess file that applied to all subdomains (and the main domain) it would need to be modified to use the REQUEST_URI server variable, instead of a backreference (since the backreference would expose the subdirectory that the subdomain points to).

For example:

RewriteEngine On

# Apply these rules BEFORE rules in child .htaccess files
RewriteOptions InheritDownBefore

# HTTP to HTTPS redirect for all subdomains
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.