I have a root domain https://example.com
and subdomain https://sub.example.com
, and a Positive SSL on the root domain example.com
My problem is that whenever I try to visit http://sub.example.com
I am correctly redirected to https://example.com
, but when I visit https://sub.example.com
, I am not redirected. How can I also redirect https://sub.example.com
to https://example.com
?
.htaccess
in subdomain:
# BEGIN WordPress
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 6 hours"
ExpiresByType image/jpeg "access plus 6 hours"
ExpiresByType image/gif "access plus 6 hours"
ExpiresByType image/png "access plus 6 hours"
ExpiresByType text/css "access plus 6 hours"
ExpiresByType application/pdf "access plus 1 week"
ExpiresByType text/javascript "access plus 6 hours"
ExpiresByType text/html "access plus 10 minutes"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 3 hours"
</IfModule>
Header set X-Endurance-Cache-Level "2"
# END WordPress
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.sub\.example\.com$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
</IfModule>
Any help or suggestions would be much appreciated.
Your conditions are only looking HTTP requests
RewriteCond %{HTTP_HOST} ^sub\.example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.sub\.example\.com$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
Try to add same rules with HTTPS
RewriteCond %{HTTPS_HOST} ^sub\.example\.com$ [OR]
RewriteCond %{HTTPS_HOST} ^www\.sub\.example\.com$
RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]