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]
Best Answer
That should work fine, however, I'd probably use an A record, rather than a CNAME record to save that extra lookup.
Also, bear in mind that this will resolve them to www.domain.com. but not redirect. So, for example, if a user starts accidentally using ww.example.com - they will be lead to believe that this is the correct web-address, which could cause issues further down the line. You will need to resolve this on your web server, though.