If a user enters ww2.domain.com he should be redirected to www.domain.com. This should be possible for all sort of subdomains (e.g. xxx.domain.com, ww.domain.com, ...). How should I set up the DNS record?
Will this DNS entry work?
*.domain.com. CNAME (Type) 3600 (TTL) www.domain.com.
Solution:
There were several steps involved for this. First I created DNS wildcard entries like this
*.domain.com A 3600 1.2.3.4
domain.com A 3600 1.2.3.4
Than in the webhost settings I added a SEO redirect *.domain.tld => www.domain.tld
with R=301,L. Furthermore for the alias domains the wildcard for the subdomains has been activated. Than I added in my htaccess
the following rules:
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{http_host} ^www\.some-domain\.com [NC]
RewriteRule ^(.*)$ http://www.main-domain.com [R=301,NC]