If you want to 301 redirect non-www to www in .htaccess Write the following code in .htaccess  file (if not just create a file name “.htaccess”

Here’s the correct solution which supports https and http: