- Example 1 - Redirect from olddomain.com to www.newdomain.com:
RewriteEngine On
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
This is useful when you use www.newdomain.com as your new domain name (see also this article about redirecting www and non-www domains). If not - use the code of example 2.
- Example 2 - Redirect from olddomain.com to newdomain.com:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R=301]