Your SSL certificate is not valid for www.mywebsite.com
because you have not issued it with it included. That means that, you did not enter www.mywebsite.com
when issuing your SSL certificate.
How to solve this:
If you are using a service like LetsEncrypt, you can just reissue it with www.mydomain.com
included.
If using self-signed cert:
If you have issued a self-signed cert, you have to reissue it with the Subject Alternative Name included.
To issue a self signed cert with the Subject Alternative Name included, do this:
- Create a file named
req.conf
, and add the following to it:
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
C = Two letter country code
ST = SomeState
L = SomeCity
O = MyCompany
CN = mywebsite.com
[v3_req]
keyUsage = keyEncipherment, dataEncipherment
extendedKeyUsage = serverAuth
subjectAltName = @alt_names
[alt_names]
DNS.1 = mywebsite.com
DNS.2 = www.mywebsite.com
And run:
openssl req -x509 -nodes -days 730 -newkey rsa:2048 -keyout cert.pem -out cert.pem -config req.conf -extensions 'v3_req'
And use those certs.
BTW, if still not working:
Btw, change:
# HTTP to HTTPS canonical redirect
RewriteCond %{HTTP_HOST} mywebsite.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://mywebsite.com/$1 [R=301,L]
To:
# HTTP to HTTPS canonical redirect
RewriteCond %{HTTP_HOST} !mywebsite.com [NC,OR]
RewriteCond %{SERVER_PORT} 80
RewriteRule (.*) https://mywebsite.com/$1 [R=301,L]
To redirect everything that is not https://example.com
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…