How to let non-www redirect to www domain?

Today I installed DEDECMS, a very popular PHP CMS open source system, I found I can not let non-www redirect to www domain. Say my domain is glassespeope.com, then I can not let http://glassespeople.com redirects to http://www.glassespeople.com. I tried to google, and found the following code can resovle the problems:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^glassespeople.com
RewriteRule (.*) http://www.glassespeople.com/$1 [R=301,L]

Save the above code in a .htaccess file, and upload this .htaccess to your web hosting root. Everything is OK!

King Php Science Welcome, you are from: 54.224.158.232