La regla es muy sencilla y aquí te damos algunos ejemplos:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
</IfModule>
No todos los sitios funcionan de la misma forma y no todas las configuraciones de php y otros módulos permiten el uso de las mismas reglas. Es por eso que aquí te dejamos algunas alternativas para lograr el mismo resultado pero con reglas diferentes:Alternativa 1
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://dominio.tld%{REQUEST_URI} [R=301,L,NE]
Alternativa 2 RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Cuidado, en los casos en que utilizamos "dominio.tld" el código debe ser reemplazado por tu dominio real.