.htaccess 301 redirect many pages to one, excluding known pages-Record and share programming errors

I have been poking around online for some time and have yet to find my specific solution. Any help is greatly appreciated. My old site redirects to the usual pages (contact, home, about, etc.) on the new site just fine. However there are so many old backlinks from various sites out there that continue to link to the old site and they are now throwing 404 errors. I would rather that the old links simply go to the home page instead. Ultimately, I would like to be able to create redirects for the whole lot of unknown pages/links out there without affecting the good 301 redirect to the usual pages noted above. Example:

oldsite.com/contact redirects to newsite.com/contact (works just fine)

oldsite.com/somerandomlink.html (results in 404 and there are many of these links out there – client has had several older sites and backlinks turn up from all over)

Is it possible to tell ALL random links to instead go to newsite.com via the .htaccess file without disrupting existing 301 redirects? A straight forward .htaccess example would be great.

  1. Try this

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

Originally posted 2013-10-25 05:05:34.