Try this code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
## Redirecd index.html & php to /
RewriteCond %{THE_REQUEST} /index\.(html|php) [NC]
RewriteRule ^(.*?)index\.(?:html|php)$ /$1 [L,R=302,NC,NE]
## 301 Redirect from non-www to www version
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
## Return 404 status code and display 404.html
ErrorDocument 404 /404.html
</IfModule>