The goal is to permanently redirect BOTH HTTP and www to https://example.com on a shared hosting service with an active SSL.
Several attempts; some involving a rule like:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
and other attempts involving, for example, rules like the StackOverflow post by Rahil Wazir involving:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{SERVER_PORT} !^443
RewriteRule ^(.*)$ http://example.com/$1 [L, R=301]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteCond %{SERVER_PORT} ^443
RewriteRule ^(.*)$ https://example.com/$1 [L, R=301]
Thus far, no attempt has completely met the goal. Can you help?
Note that https://www.example.com should also permanently redirect to https://example.com.