Please don't close for being a duplicate, I have already tried the other answered questions and am still having issues.
First, I know why the certification for the site breaks when using www
. The cert is for just example.com
not www.example.com
, and adding www
is technically a subdomain and therefore breaks the cert, causing browsers to do the whole 'bad/untrusted cert' thing.
My situation is that I have certs for just example.com
, and sometimes Google indexes pages using www.example.com
. This is obviously an issue because when people search for things on my site, it is rather annoying and bad press to encounter the 'bad cert' thing.
Is there any possible way to force https access and remove the www
? I have tried using htaccess to do so, but am still running into the bad cert issue.
It should be noted that my current htaccess does what it needs to (force https/no www) when initially connecting via http. It only fails to do so when the initial connection is made with https and using www (presumably the browser is refusing the connection before htaccess has a chance to act).
Current htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
Alternatively, if there was a way to keep Google from indexing the pages with www, that would also be an acceptable workaround for me.