Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

share|improve this question
    
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 at 15:27

4 Answers 4

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)

share|improve this answer
    
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 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 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 at 14:36

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.

share|improve this answer

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

share|improve this answer

If you have FTP access to mydomain.com you could just put in a .htaccess file with the redirect. You don't need access to the apache configuration for this.

share|improve this answer
    
This won't help without the DNS configured correctly, and that's depending on if you want a redirection or not. –  Mark Henderson Jul 12 '10 at 5:39

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.