Apache: Redirecting www- to non-www

Use these  lines in your configuration file:

RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule .? http://example.com%{REQUEST_URI} [R=301,L]

You need mod_rewrite for this and use RewriteEngine on.

(Found on sitepoint.com)