Comparing the above code with this code (Moving from .html to Kirby .php and SEO - #9 by sebastiangreger)
then should it be the following, to turn on https and www BUT only when live and not locally?
RewriteCond %{HTTP_HOST} !^localhost(?::\d+)?$ [NC]
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
Update: on first look, this seems to work. I’ll test it more extensively.