Using htaccess to accomplish the 301 redirect is highly suggested due to it being fairly convenient to manage, rather than setting redirects on each individual page, you can simply add the redirect code to the .htaccess file.
Here is how to do it:
Create a file on the root directory of your website, name it ".htaccess".
Open the .htaccess file using notepad or what ever text editor that you prefer.
Add this into the .htaccess file, save it and then upload it to your web server:
I won't translate it for you, but what I will say is don't even attempt it
if you don't know what you are doing.
Too many times I see, "just create an .htaccess file and upload it"
You should never upload a .htacces file without knowing what you are doing.
The Following User Says Thank You to UKSBD For This Useful Post:
The redirect you show is for page redirect. You mention canonical issues where both non www and www urls display the same page essentially causing duplication.
.htaccess is a Linux file but your site is on a Microsoft-IIS/6.0 server so .htaccess won't work for you. I know nothing about Windows servers so I'm afraid I can't help, though Phil (OpenMind) will be able to show you how to do it.
301 redirects in IIS have to be set on the server itself unless your host provides a control panel for doing so. It can be done with scripting but setting in IIS is the best route.