Create .htaccess inside document root and add
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
The first RewriteRule does permanent redirect (301) to traffics if it starts with www to https://example.com
The second RerwiteRule does permanent redirect (301) to traffics if it’s an http request to https://example.com
Www, non-www, https and non-https are treated different site by search engines.
So it’s important to unify them for SEO purposes.
Reference: https://moz.com/community/q/302-or-301-redirect-to-https