Problem

When I view my website using a domain aliases I get an SSL error similar to the below;

Chrome:

“Your connection is not private”

Microsoft Edge / Internet Explorer:

“There is a problem with this website’s security certificate.”

Safari:

“Safari can’t verify the identity of the website”

Cause

This error can occur if you have an SSL certificate on your primary domain name and attempt to view a URL using a domain aliases your browser. The browser is unable to match the website to the supplied SSL certificate and returns the error message.

Resolution

Enter the below into your .htaccess file;

# ----------------------------------------------------------------------
# | Redirect all domains to `http://` to avoid SSL warning notices     |
# ----------------------------------------------------------------------

# If you have an SSL certificate on your primary domain name and attempt
# to view a URL using a domain aliases your browser will return an SSL error. 
# as it is attempting to verify the site identity using the SSL cert assigned
# to the main domain name. To fix this we redirect all domain aliases to the
# non-SSL `http://` version of the URL and follow-up by redirecting `https://`
# version of the URL.

<ifmodule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /
 Rewritecond %{HTTP_HOST} !^www\.example\.com [NC]
 RewriteRule (.*) http://www.example.com/$1 [R=301,L]
</ifmodule>

# ----------------------------------------------------------------------
# | Forcing `https://`                                                 |
# ----------------------------------------------------------------------

# Redirect from the `http://` to the `https://` version of the URL.
# https://wiki.apache.org/httpd/RewriteHTTPToHTTPS

<ifmodule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{HTTPS} !=on
 RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</ifmodule>