Redirect non-www to www in .htaccess

Below snippet shows how to redirect a site from non-www to www

or

or

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