Redirecting From One Domain To Another Using Mod Rewrite
Use the following rules in your Apache configuration (or your .htaccess file) to redirect all traffic from one domain to another. This also keeps the query string in place so that the user isn't just dumped to the homepage.
RewriteEngine on RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com%{REQUEST_URI} [L,R=301]
These rules are mod_rewrite dependent, so you'll need that module enabled in your Apache install.