Setting up multiple domain aliases

January 10, 2014 5.7k views
I have five domain names, pointing to the same droplet . One domain is the primary one and the other four are just legacy aliases. There is also bunch of subdomains. How do I set up the DNS system that any subdomain and legacy domain redirect correctly to the subdomain at the primary domain?
6 Answers
that's not DNS, it's apache/nginx.
Yes, partially it is. Yet, if the domain names and subdomains are not configured correctly, the request will never get to the web server. Thus, original question stands.
To clarify further, I'd like a solution that doesn't require me to duplicate all the subdomain data for all the domains by hand. Keeping say 10 subdomains over 5 domains is 50 steps and prone to errors in the long run.
Not sure how you could automate the process. The only way I can think of is outlined, here: How To Set Up a Host Name with DigitalOcean.
by Etel Sverdlov
This article walks you through setting up the DNS for your site. The tutorial includes steps to set up an A records, point your nameservers, and provides some information about MX records.
It seems there is no better way than putting wildcard domain redirection "* ->" in the DNS and then handling the requests by redirecting non-maindomain requests in nginx/apache conf.

Putting a wildcard in the DNS causes the non-canonical domain names being used, thus you require a server-side redirect to canonical domain to make it "pretty". This is not an optimal solution, but maybe one day DigitalOcean will provided us a DNAME DNS redirection.
You may find this article helpful as well:
by Assaf Gordon
Here's some documentation on how to set up and test DNS subdomains with DigitalOcean's DNS panel.
Have another answer? Share your knowledge.