Force Users to Use WWW for Non WWW Versions

A basic htaccess snippet on how to force users to use www on non www version of their projects.

This is an .htaccess rule to force users to use www on non www website version.

# Redirect non-www urls to www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]