5

This is not really a programming question, it's more about settings that I can alter visually.

I have bought a domain and am wondering how I can get it work in such a way that everything before the .example.com except for things I've already set (like pop.example.com) are being forwarded to www.example.com (or *.example.com).

so stuff like this:

  • pop.example.com
  • ftp.example.com
  • my.example.com

Goes to the appropriate URL, but:

  • idontknowwhattheurlwas.example.com
  • ivemistypedsomething.example.com
  • bla.example.com
  • 123.example.com

Are aliases for www.example.com.

The options for adding a rule inside the DNS configuration are:

  • A
  • AAAA
  • MX
  • TXT
  • CNAME
  • SRV

Or perhaps it's better to do this with .htaccess? and if so, how should i configure it?

xaddict
  • 152
  • 1
  • 6
  • This is probably better asked at http://serverfault.com/, but do you have access to the zone file? Wild card DNS is easy to set up if you can edit the zone file directly. –  Aug 27 '10 at 12:49
  • I've only got access to a control panel with visual tweaking of the DNS and the top-level .htaccess – xaddict Aug 27 '10 at 12:50
  • I think the dupe question has a clearer answer: http://serverfault.com/questions/175225/how-to-set-up-a-dns-to-use-a-catch-all-address/175239#175239. Perhaps the two questions could be merged? They are, after all, exactly the same question, word for word. – TRiG Aug 29 '11 at 13:36

4 Answers4

4

You need both:

In DNS zone setup an entry (the last, the best)

*.your_domain.foo.  IN  A   999.999.999.999 # correct this csi-like ip

The last dot in domain is very important.

That will match any.your_domain.foo to your IP. you can place other entries for other subdomains / ip's before.

And in apache / other web server you mus setup a vhost or something to handle all the requests an set ServerAlias / ServerName to

ServerAlias *.your_domain.foo

Again place this Vhost the lasts, defining any existing vhosts in your_domain.foo before the default one.

Apache loads config files using an ascii ordered scheme so put this in a 099_default file and prepend other by 050_

In your case, the DNS should let you to use a *.yourdomain.foo. in zone definition and I think you can archieve the apache part using mod_rewrite, if it is enabled. I think that There are some ways of simulate virtual hosting usin rewrites with the SERVER_NAME variable as a condition. Check http://httpd.apache.org/docs/2.3/rewrite/vhosts.html. I haven't tried it.

theist
  • 1,229
  • 2
  • 10
  • 24
3

You do this in DNS. If you have a sane (bind-like) dns server you want to add something like this to the configuration for your zone:

server.example.com.  A      192.168.1.1
*.example.com.       CNAME  server.example.com.

It creates an alias for the wildcard and points it to the address of the server.You can also do it directly:

*.example.com.       A      192.168.1.1

But for management reasons the first solution is typically better. Once this is done you create a catch-all vhost that mirrors your www.example.com host.

pehrs
  • 8,789
  • 1
  • 30
  • 46
0

Use a star:

*.example.com CNAME www.example.com www.example.com A 192.168.1.5

Yves Dorfsman
  • 221
  • 2
  • 6
0

It's named jocker. In your DNS configuration put all the names you want and then add the line

* CNAME www.example.com

All the unknown names will be CNAMED to www.example.com

Dom
  • 6,743
  • 1
  • 20
  • 24