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:
demo.example.com
demo.example.com/site1
demo.example.com/site2
demo.example.com/site3
demo.example.com/site4
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!