Try searching using WebmasterWorld site search (link at top of page) for "301 domain redirect" plus your server name, e.g. Apache, IIS, etc. We've had many threads on this that will help you to define and narrow - or even answer - your question. But the methods available all depend on your server type.
I have already done just that. a 301 redirect will not suffice for my problem since I need the query string to be maintained. If I did a 301 I would just have to redirect all traffic from some-widgets.com/querystring to www.widgets.com with no query string.
will preserve both the requested page and the query string through the use of backreferences $1 and %1, and redirect requests to any domain other than www.maindomain.com to www.maindomain.com. As long as the domains in the first and last line match - allowing for the regex syntax requirement of escaping periods in the RewriteCond - this will work.
If your domains are hosted on separate virtual servers, the same thing will work, but you can/should delete the first RewriteCond.