Many developers face a frustrating scenario: their web application works perfectly when accessed via www.example.com
, but fails when users try the root domain example.com
. This typically occurs when hosting providers only supply a CNAME target (like yourprovider.com
) rather than static IP addresses.
RFC 1912 and 1034 explicitly state that CNAME records shouldn't coexist with other records at the zone apex. When your DNS provider enforces these standards, you'll encounter errors like:
;; ERROR: CNAME and other data at a node
Here are proven solutions we've implemented for clients:
Solution 1: DNS Provider-Specific ALIAS/ANAME Records
Modern DNS providers offer pseudo-CNAME solutions:
; Cloudflare example example.com. IN A 192.0.2.1 ; Proxy enabled www.example.com. IN CNAME yourprovider.com.
Solution 2: Web Server Redirection
Configure your origin server to handle the redirect:
<VirtualHost *:80> ServerName example.com Redirect 301 / http://www.example.com/ </VirtualHost>
Solution 3: Load Balancer Configuration
For AWS users, Route 53 offers alias records:
resource "aws_route53_record" "root" { zone_id = aws_route53_zone.primary.zone_id name = "example.com" type = "A" alias { name = "yourprovider.com" zone_id = "Z2FDTNDATAQYW2" # CloudFront evaluate_target_health = true } }
Each approach has tradeoffs:
- DNS-level solutions add minimal latency
- HTTP redirects create additional roundtrips
- Some CDNs charge extra for root domain handling
- Verify your DNS provider's capabilities
- Test with
dig +trace example.com
- Monitor for DNS propagation delays
- Set appropriate TTL values (300-3600 seconds)
Many developers face this common DNS dilemma: your hosting provider gives you a CNAME target (like your-site.provider.com
) for your subdomain (www
), but the root domain (example.com
) can't be a CNAME due to RFC compliance. This creates accessibility issues when users omit the www
prefix.
According to DNS RFCs (1034, 1912, 2181), a CNAME at the root would conflict with other essential records like MX, TXT, and NS. The DNS specification requires the root to be an A or AAAA record.
Here are three proven approaches:
1. DNS Provider-Specific ALIAS/ANAME Records
Modern DNS providers offer pseudo-CNAME solutions:
# Cloudflare example (using CNAME flattening)
example.com. 300 IN CNAME your-site.provider.com.
# AWS Route 53 example
example.com. 300 IN ALIAS your-site.provider.com.
2. Traditional A Record with IP
If your provider offers static IPs:
example.com. 300 IN A 192.0.2.1
www.example.com. 300 IN CNAME your-site.provider.com.
3. HTTP Redirect Solution
Configure your web server to redirect root to www:
# Nginx configuration
server {
listen 80;
server_name example.com;
return 301 $scheme://www.example.com$request_uri;
}
Use these diagnostic commands:
dig example.com +nostats +nocomments +nocmd
nslookup example.com
curl -I http://example.com
Major DNS services handle this differently:
- Cloudflare: Automatic CNAME flattening
- AWS Route 53: ALIAS records
- DNSimple: ANAME records
- Google Cloud DNS: Requires A records