You can use this and put it on your htaccess file to comply with https://hstspreload.org. put this in your .htaccess file.
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L,E=HTTPS:1]
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" env=HTTPS
first, it will do redirection for non https to https. and redirect non www https to www https with HSTS header.
(http://example.com -> https://example.com -> https://www.example.com - with HSTS header)
Tested and comply with https://hstspreload.org