It looks like various permutations of this question have been asked before, but it looks like all of the answers have specific idiosyncrasies that don't apply to my situation, or just don't work.
So, here's what I'm after...
I would like these three URLs:
... To all redirect to:
From another answer, I tried this;
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
But, that doesn't redirect from https://www.example.com to https://example.com
So, the result is a certificate warning (since my certificate is only valid for example.com, not www.example.com).
I also tried this (from https://html5boilerplate.com/)...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ %{ENV:PROTO}://%1%{REQUEST_URI} [R=301,L]
</IfModule>
... But that didn't work either:
- http://www.example.com was redirected to https://www.example.com
- https://www.example.com was not redirected
Thanks in advance for your help.