Steps to prevent the same are :
1) Edit your .htaccess file (found in the root directory of your website folder). If the file doesn’t exist, please create a new file and name it as .htaccess
2) Put these 2 rules at the end of the file :
RewriteCond %{HTTP_HOST} !^www.your-domain.com$
RewriteRule ^/?(.*) http://www.your-domain.com/$1 [QSA,R=301,L]
Note:
You can put https in place of http if your website works on https.
Done !!