1. Create an .htaccess file in your public_html directory. If you already have an .htaccess file in the public_html directory, you can modify it.
2. Add these lines to the file
# Add www to any URLs that do not have them:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
3. Try to enter URLs with no www prefix, it will now automatically redirect you to your websites!
Source: https://www.a2hosting.com/kb/developer-corner/apache-web-server/adding-or-removing-the-www-prefix-in-domain-urls