It’s a repeating topic that you can have tons of information around the world. However, it just happened to my working place that create many “discussions”. Not an interesting topic.
This page: How to Redirect from Your Root Domain to the WWW Subdomain and Vice Versa Using mod_rewrite explained why you wish to do so and the traditional way of doing so when you host your Web site under apache. This page: Back to Basic: DNS ALIAS records briefly explain why many people would say you cannot do so in DNS.
TL;DR
- You want to do so mainly due to search engine, or say in a more modern wording: SEO (search engine optimization).
- Traditionally, DNS won’t allow you to set the root domain with CNAME because, by the specification, you cannot specify another DNS entry of any type once you’ve define it as CNAME. The root domain, specify by “@“, normally, is used for MX or SOA and it would violate the rule.
Traditional Workaround
The situation is simple when you have your only Apache hosting your Web site. Just add a .htaccess entry as specified in the like above. This comes fishy when you have an CDN / external Web hosting / CMS hosting internally or externally without an explicit Web server to make such configuration. However, you can always set an individual Apache (ok, you can do the same with NGINX) to do the same traditional 301 redirect by pointing your root domain to the IP of the Apache using A record.
Set on the DNS Services
If your DNS server support domain ALIAS, you can easily set the root domain entry to ALIAS to www of your domain (see the link about). The argument I face here is… Hey, your named won’t support this and please don’t set the CNAME for the rule domain, genius.
My bad and update here. Both CNAME and ALIAS in DNS is not a good option in concern of SEO:
CNAME vs 301 Redirect
ALIAS vs 301 Redirect
In short, both will result in serving your root domain with your content in the destination, but under the root domain. You will need a proper 301 Redirect to notify the search engine that your root domain is actually moved to WWW. I assume when you reading this, you know why you need to do so (but I believe many traditional IT staff won’t though,) so I won’t explain it in details here. Likely if you are reading this, actually it’s your marketing or corporate communication staff catching your IT to do that and they can’t explain clearly the technical differences…. 😀
Modern DNS, for example AWS Route 53, Google Domain and CloudFlare DNS. I don’t detail their documentation here for their proprietary implementation. Something unfortunate to Azure DNS users that the alias handling only apply to Azure CDN endpoint (to this point of time). You may need to seek alternative.
Set on the F5 BigIP
Oh yes, if your site have F5 BigIP as on-premises load balancer, it will be more sensible to do a redirect with iRules without setting an extra Web server setup. Go google their documents and I’m sure it is listed in the FAQ.
Some CMS / CDN Setup
Some CMS / CDN hosting may support this, check with your vendor.
Afterword
Anyway. I’m using Google Domain in this Web site. So I have already done a simple Domain Redirect to serve the purpose. (Not an advertisement.)
Simple life…. 😀
Read More