Setting up multiple domain aliases

Posted January 10, 2014 13.3k 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?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
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.
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: