Reputation: 2505
I am trying to redirect all subdomains to a new domain with htaccess.
All subdomains with any path get forwarded:
y.domain.com/anything --> y.domain2.com/anything
Don't forward the main domain or www:
domain.com --> domain.com
www.domain.com --> www.domain.com
I have tried the following but does not seem to be working:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
RewriteRule ^(.*)$ http://%1.domain2.com/ [L,R=301]
Upvotes: 1
Views: 63
Reputation: 785256
You may use this rule:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?!www\.)(.+)\.domain\.com$ [NC]
RewriteRule ^ http://%1.domain2.com%{REQUEST_URI} [L,R=301,NE]
Make sure to use a new browser to test this change or completely clear browser cache.
Upvotes: 0