I currently have a website built on Angular and hosted on Apache2 on a Ubuntu server and recently changed the SSL certificate. I keep getting 'NET::ERR_CERT_COMMON_NAME_INVALID' if I go to https://example.com/public/home
but no error when going to https://www.example.com/public/home
.
One strange thing is if I write the URL as https://example.com/public/home/
, it properly redirects to https://www.example.com/public/home
. Also, going to example.com
redirects to the correct one.
I've shared below my current htaccess:
RewriteEngine on
# Don't rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
# Rewrite everything else to index.html to allow html5 state links
RewriteRule ^ index.html [L]
#http to https
RewriteEngine On
RewriteCond %{HTTP_HOST} example.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
What should I change for the correct redirection for https to https www?
Resolved after getting an SSL certificate for both example.com and www.example.com after John Hanley's comment. Thanks.