Assuming apache - you would only use 1 of these methods and I'd suggest checking google results to see which one is indexed more
#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} example.com [NC]
RewriteRule (.*)$ http://www.example.com/$1 [L,R=301,NC]
#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} www.example.com [NC]
RewriteRule (.*)$ http://example.com/$1 [L,R=301]
Your host should be able to advise you if you hit problems
Cheers
Paul