3

I have an app that is roughly fractured between a server serving front end and one serving an API. We'd like to add a wildcard to catch usernames on the subdomain and direct those to the front end server. So my URLs map like so:

Server that serves front-end files is mapped by https://example.com and https://www.example.com

Server for the API is mapped by https://api.example.com

We also have a forum, demo, etc at domains like https://forum.example.com and https://demo.example.com

Right now this is all straightforward using ALIAS records in DNSimple.

What is the best way to capture https://username.example.com and map it to the front-end server? We will need it to be a wildcard e.g. *.example.com, but we don't want to direct api, forum, demo, etc to that server.

Is there a way to set hierarchies or priorities at the DNS level so that it checks for the named matches first and then moves on to wildcard if nothing is found?

Tyler
  • 11,272
  • 9
  • 65
  • 105

1 Answers1

7

The way to go is exactly the one you considered. You should add a wildcard DNS record

*.example.com

that points to the IP (A) or hostname (CNAME) you want. The rule is that if there is a specific record matching the query, our DNS server will server it. Otherwise, we will fallback to the wildcard.

In other words, if you have a wildcard in place and a client asks for api.example.com, we will serve the api DNS record and not the wildcard. Specific records have higher priorities over wildcards.

Simone Carletti
  • 173,507
  • 49
  • 363
  • 364
  • OK, I was hoping this would be default behavior but you never know, and I didn't want to just try it on the site and see. Thanks! – Tyler Feb 24 '15 at 16:36