.htaccess new domain name + subdomains

I seem to be having a lot of .htacces questions lately, it’s about time I’d just get it!

My current problem is moving to a new domain name.

I have a site example.com with multiple subsites in demo.example.com:

It’s a rather complicated Drupal multisite setup.

Anyways, I got a new domain name and I know this code is good for moving to a new domain name but it does not take subdomains into account:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\\.)?oldsite\\.nl$ [NC]
RewriteRule ^(.*)$ http://www.newsite.com%{REQUEST_URI} [R=301,L]

This particular code appends %{REQUEST_URI} at the domain name instead of /$1 like in the SEO FAQ. I cannot use the latter option because somehow it results in double slashes after the redirect.

I would like to adapt the above code to work on my subdomains, I tried copying the 2 lines and modify the middle 2 like so:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\\.)?oldsite\\.com$ [NC]
RewriteRule ^(.*)$ http://www.newsite.com%{REQUEST_URI} 
RewriteCond %{HTTP_HOST} ^(demo\\.)?oldsite\\.com$ [NC]
RewriteRule ^(.*)$ http://demo.newsite.com%{REQUEST_URI} [R=301,L]

But unfortunately this resulted in all requests going to demo.newsite.com including the ones from www.oldsite.com

Any help would be greatly appreciated!

Ok I just found out I had been getting the code right a long time now but it didn’t work because the subdomain simply wasnt recognised on the domain name that I was experimenting with. Don’t even know why, but this is why I hate webserver management! too many places you got to check up on!

proper code for me:

RewriteEngine on
RewriteCond %{HTTP_HOST} demo\\.alldrupalthemes\\.com
RewriteRule (.*) http://demo.sooperthemes.com%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\\.)?alldrupalthemes\\.com$ [NC]
RewriteRule .? http://www.sooperthemes.com%{REQUEST_URI} [R=301,L]

I run this code in httpd.conf via a customization in DirectAdmin (as opposed to in a .htaccess file).

no-one here to save me while Im breaking my head over dklynn’s excellent article on mod_rewrite? (though I hate the animated links to show/hide text)