0

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]
testing
  • 175
  • 1
  • 13

2 Answers2

5

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.

Dan
  • 15,430
  • 1
  • 36
  • 67
  • Rarely will there ever be an extra lookup within the domain itself. DNS servers make it their business to consolidate responses where possible. – Andrew B Jun 24 '13 at 13:35
0

If you want to redirect all subdomains to your www subdomain, you can set the A-Record for the wildcard(and the @ record, if you want the domain without any subdomain redirected, too).

But keep in mind you have to do the redirect on the server!

Izzy
  • 795
  • 2
  • 8
  • 31