I using below code in the htaccess file to redirect www to non www domain and the requirement as below.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^w
I use this:
RewriteEngine On
# the following line is only needed, if HTTP and HTTPS share the same config
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_FILENAME} !^/.well-known/
RewriteRule .* https://wiimmfi.de$0 [R=301,L]
I excluded /.well-known/
to update the let's encrypt certificates.
Inside a <directory>
or for .htaccess:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_FILENAME} !^.well-known/
RewriteRule .* https://wiimmfi.de/$0 [R=301,L]