How to use .httaccess to eliminate redundant domains indexed in Google

Every page of my website mysite2.com is indexed in Google twice.
The redundant entries are URLs that use my old domain name mysite1.com.
I am trying to use wildcard redirects in my .httaccess file to have any
URL with the old domain name redirect to the new domain.
I tried the following:
Redirect 301 / http://www.mysite2.com/
but this caused a server error.
I suspect the error was caused because I have a few redirect statements
that redirect a few special pages to a 3rd-party website because those special
pages really have moved somewhere else.
Also, there are already several hundred redirects in my .httaccess file because
I recently migrated my .HTML pages to .PHP pages with more SEO-friendly hyphenated
names.
I need a wildcard solution to make sure that any URL that uses the old domain name
gets redirected to the new domain name.
I also need to know if I need to use rewrite statements in conjunction with redirects.
Please help.

Joe,

Welcome to SitePoint!

The response to your question (assuming co-located files) is simply to test for the new domain and, if not being used, redirect:

RewriteEngine on

RewriteCond %{HTTP_HOST} !^newdomain\\.com$ [NC]
RewriteRule .? http://newdomain.com%{REQUEST_URI}

You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.

One of the first things to learn about using .htaccess is DON’T! If you have hundreds of lines, you’re abusing your server and should be banned from shared servers (and VPS’s). If you seriously need those lines of code, have your host add them to your httpd-vhosts.conf file or into the httpd.conf while specifying your account.

Regards,

DK

David,
Thanks for your excellent help and the link to the tutorial! Also thanks for the advice about having too many statements in my .httaccess file. I am pursuing that issue with my host.
Thanks,
Joe

Joe,

:tup:

Regards,

DK