Non-WWW to WWW Redirection and No SSL to SSL – htaccess

I'm trying to redirect my WordPress site from no www to WWW and no SSL to SSL permanently.

Here is the code I use:

RewriteEngine On
RewriteCond% {HTTPS}! = On
RewriteRule ^ (. *) $ Https: //% {HTTP_HOST}% {REQUEST_URI} [L,R=301] 

RewriteEngine On
RewriteCond% {HTTP_HOST} ^ example  .com [NC]
RewriteRule ^ (. *) $ Https://www.example.com/$1 [L,R=301]

I wonder if the code is correct or if we can do it better. I mean, it seems to work, but PageSpeed ​​says I should avoid so many redirects.