Migrate Multiple Domains to New Domain Using .htaccess

Ok so you have multiple domains all pointing to your main domain where your site lives.

But now you want to change the main domain, so you need to redirect all requests, for all the alias domains, to the new main domain and generate a 301 response so search engines and browsers know that the pages have all been moved permanently.

You also want to retain the page urls intact.

This worked well for me:

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

This works like this:

If the host (domain) is anything other than your new domain, capture the page URL, rewrite the host domain to the new one, add the page url and send a 301 response.