Save yourself the trouble of trying to determine whether you’re using Apache 1.x or 2.x with
RewriteEngine On
[COLOR="Blue"]# if the request is for olddomain.com ...[/COLOR]
RewriteCond %{HTTP_HOST} olddomain.com$
[COLOR="Blue"]# ... rewrite it to newdomain.com preserving the URL [COLOR="Red"]using THE ORIGINAL {REQUEST_URI}[/COLOR]
RewriteRule .? http://www.newdomain.com%{REQUEST_URI} [L,R=301]
RewriteEngine On
[COLOR="Blue"]# if the request is for olddomain.com ...[/COLOR]
RewriteCond %{HTTP_HOST} olddomain.com$
[COLOR="Blue"]# ... rewrite it to newdomain.com preserving the URL using (.*) and $1[/COLOR]
RewriteRule (.*) http://www.newdomain.com/$1 [L,R=301]