0

I'm looking to get my mydomain.com and *.mydomain.com redirected to sub.domain.com only using DNS if at all possible. This is all the same domain.

So that:

  • www.domain.com -> sub.mydomain.com

  • mydomain.com -> sub.mydomain.com

  • anything.mydomain.com -> sub.mydomain.com

Adam Arts
  • 3
  • 1
  • You can use a CNAME for `anything.mydomain.com` and `www.domain.com`, but not for the root domain. You will need a webserver to issue a 30x redirect for that. – jordanm Feb 27 '17 at 16:51
  • 2
    DNS does not perform redirects. You will need to get an HTTP-aware server involved to do this. – EEAA Feb 27 '17 at 16:51
  • @jordanm Thanks, how would I set it so that *.mydomain.com redirected? Would I just put *. in the name field? – Adam Arts Feb 27 '17 at 16:55
  • Well there's the DNS `DNAME` record but I'm not sure how that would fly for `example.com` being "dnamed" down to `sub.example.com` – thrig Feb 27 '17 at 16:57
  • Would this be easier to be done with a htaccess file? – Adam Arts Feb 27 '17 at 17:02
  • Point \*.mydomain.com to a webserver (A and/or AAAA records) using wildcard DNS records. Configure webserver to serve mydomain.com as main website and anything else (*.mydomain.com) as 30x redirect to scheme://mydomain.com (Apache can do this, using ServerAlias *.mydomain.com. Nginx can probably do it as well). – parkamark Feb 27 '17 at 17:04

1 Answers1

0

A wildcard entry on the delegated name server for mydomain.com allows all FQDN's to resolve using the same A record. A blank (or @ character) allows the domain itself to resolve to the IP. Multiple A records to a single IP is allowed.

i.e.

mydomain.com.   300 IN A 10.1.2.3
*.mydomain.com. 300 IN A 10.1.2.3

Is all that would be needed. No CNAMEs required.

billq
  • 326
  • 1
  • 4
  • 1
    This way one will get duplicate content issues, since all domains will be serving the same content. 301 redirect is the correct way to handle these. – Tero Kilkanen Feb 27 '17 at 23:25