3

Is it possible to point wildcard subdomains to a top level domain via DNS settings alone?

I would like to have *.mydomain.com redirected to mydomain.com.

mydomain.com is hosted on a 3rd service. I do not have access to any of my site's apache configuration files.

Thank you, Malcolm

  • Can you clarify what the desired result is? You can have a wildcard in DNS but that will just make all those names resolve to some address. In the context of a web site you would still most likely want to do a http permanent redirect to have everyone sent to the same address. – Håkan Lindqvist Jul 19 '14 at 15:27

3 Answers3

2

At a DNS technical level, sure you can have:

*.example.com. IN CNAME example.com.

Although a better configuration would be:

$ORIGIN example.com.
@      IN SOA ( ... )
       IN A n.n.n.n     ; put your server IP here
www    IN A n.n.n.n     ; and here
*      IN CNAME www

That will ensure that people doing a lookup for the SOA or MX records of foo.example.com don't get an unexpected answer.

However if your web server isn't set up to expect the wildcarded host names that people start using to point at, they'll just get error pages.

For that to work you need something like:

<VirtualHost .....>
ServerName wwww.example.com
ServerAlias example.com
ServerAlias *.example.com

</VirtualHost>

and that has to be in the main config, not in a .htaccess file.

Alternatively, if the intent is that all wildcard subdomains end up at the same site, use an HTTP-level redirect such that all URLs end up with the client redirected to a preferred canonical URL (e.g. either www or the one without any prefix)

Alnitak
  • 20,901
  • 3
  • 48
  • 81
  • Doing as explained here will leave visitors on whatever address they entered. Typically the desired result for web sites is to have one canonical name. (As for the "better configuration", why not skip the use of `CNAME` altogether?) – Håkan Lindqvist Jul 19 '14 at 15:31
  • @HåkanLindqvist yes, a redirect to the canonical site might be better, but why downvote for otherwise still useful _supplemental information_. – Alnitak Jul 20 '14 at 14:02
  • In retrospect I think you're right, I was overly set on it being a complete answer. My bad. – Håkan Lindqvist Jul 20 '14 at 14:36
1

Assuming that you can without fail set wildcard (*.example.com) in DNS on your domain (if not, you can move your domain to for example freedns service).

DNS service only translate domain to IP, i'ts not related to any service (http, ftp, smtp) so it can't redirect http request from one to different domain.

But you can:

  1. Point *.example.com to some other web/http server that supports http wildcard and redirect.
  2. Contact your http service provider to setup wildcard on their server

Additionally, most of the popular/used control panels (cPanel, DirectAdmin, ...) supports wildcard so maybe you can set this up yourself.

kolorafa
  • 96
  • 1
  • 2
0

If your DNS provider supports wildcard CNAME then this should work. See Question 44618

Mark Porter
  • 991
  • 1
  • 5
  • 12