How to Redirect Your Apex Domain to WWW (Step-by-Step Guide)
A complete guide to setting up a 301 redirect from your naked domain (example.com) to www (www.example.com) using free DNS records. Includes instructions for Cloudflare, GoDaddy, Namecheap, and verification steps.
What Is an Apex Domain Redirect and Why Do You Need One?
An apex domain (also called a root domain, bare domain, or naked domain) is your domain without any subdomain prefix. For example, example.com is the apex domain, while www.example.com is a subdomain.
An apex domain redirect automatically forwards visitors who type example.com into their browser to www.example.com. This is a 301 (permanent) redirect, which tells browsers and search engines that the www version is the canonical address for your site.
There are several important reasons to redirect your apex domain to www:
- CDN compatibility: Most CDN providers (Cloudflare, AWS CloudFront, Fastly) require a CNAME record to route traffic through their network. DNS standards do not allow CNAME records on the apex domain, so hosting your site on www makes CDN configuration straightforward.
- Hosting requirements: Many platforms like GitHub Pages, Heroku, Netlify, and Vercel work best (or exclusively) with www subdomains for custom domains.
- Cookie scoping: Cookies set on the apex domain are sent to every subdomain, which can hurt performance and create security issues. Using www keeps cookies isolated.
- SEO consistency: Running the same content on both
example.comandwww.example.comcreates duplicate content. A redirect consolidates all link equity and ranking signals to a single URL. - DNS flexibility: CNAME records on a subdomain give you more control over failover, load balancing, and provider switching without changing IP addresses.
If your website is served from www.example.com, you need a redirect on example.com so visitors and search engines always reach the right place. The simplest way to do this is with a DNS-based redirect service like ApexToWWW.
Step-by-Step: Redirect Apex Domain to WWW with ApexToWWW
ApexToWWW is a free service that handles the apex domain redirect for you. It provides a server that accepts requests on your naked domain, provisions an SSL certificate automatically, and issues a 301 redirect to your www subdomain. There is no account to create, no dashboard to manage, and no cost involved.
The setup requires only two DNS records:
DNS Records to Add
| Type | Name / Host | Value / Points To |
|---|---|---|
A |
@ |
65.21.184.101 |
AAAA |
@ |
2a01:4f9:c012:a304::1 |
The A record handles IPv4 traffic, and the AAAA record handles IPv6 traffic. Together, they route all requests for your apex domain to the ApexToWWW redirect server. The server detects your domain name from the incoming request, obtains an SSL certificate via Let's Encrypt, and responds with a 301 Moved Permanently redirect to https://www.yourdomain.com. The original path and query string are preserved, so example.com/pricing?plan=pro redirects to www.example.com/pricing?plan=pro.
Here is the general process, applicable to any DNS provider:
- Log in to your DNS provider or domain registrar where your domain's nameservers are managed.
- Navigate to the DNS management page for the domain you want to redirect.
- Remove any existing A or AAAA records on the apex domain (
@) that point to a different server. Leave yourwwwCNAME or A record intact. - Add a new A record: Set the host/name to
@(or leave it blank, depending on your provider) and the value to65.21.184.101. - Add a new AAAA record: Set the host/name to
@and the value to2a01:4f9:c012:a304::1. - Save your changes and wait for DNS propagation, which typically takes 5 to 30 minutes but can take up to 48 hours.
How to Set Up the Redirect on Popular DNS Providers
The steps above work universally, but the exact UI varies from provider to provider. Below are specific instructions for three of the most popular DNS services.
Cloudflare
- Log in to the Cloudflare dashboard and select your domain.
- Go to DNS > Records.
- Click Add Record.
- Set Type to A, Name to @, and IPv4 address to
65.21.184.101. Set the Proxy status to DNS only (gray cloud). Click Save. - Click Add Record again.
- Set Type to AAAA, Name to @, and IPv6 address to
2a01:4f9:c012:a304::1. Set the Proxy status to DNS only (gray cloud). Click Save.
Important: Make sure the proxy toggle is set to DNS only (gray cloud icon), not Proxied (orange cloud). Cloudflare's proxy will intercept the request and prevent the redirect from working correctly.
GoDaddy
- Log in to your GoDaddy account and go to My Products > DNS for your domain.
- Under the DNS Records section, click Add New Record.
- Select Type A, set Name to @, set Value to
65.21.184.101, and TTL to 1 Hour. Click Save. - Click Add New Record again.
- Select Type AAAA, set Name to @, set Value to
2a01:4f9:c012:a304::1, and TTL to 1 Hour. Click Save.
If GoDaddy has an existing A record for @ (often pointing to a parked page), edit or delete it before adding the new one.
Namecheap
- Log in to Namecheap and go to Domain List. Click Manage next to your domain.
- Go to the Advanced DNS tab.
- In the Host Records section, click Add New Record.
- Select Type A Record, set Host to @, and Value to
65.21.184.101. Set TTL to Automatic. Click the checkmark to save. - Click Add New Record again.
- Select Type AAAA Record, set Host to @, and Value to
2a01:4f9:c012:a304::1. Set TTL to Automatic. Click the checkmark to save.
Namecheap may have default parking records. Remove any existing A/AAAA records for @ that point to Namecheap's parking servers before adding the ApexToWWW records.
How to Verify the Redirect Works
After adding the DNS records, you should verify that the redirect is functioning. DNS changes propagate at different speeds, so allow at least 15 minutes before testing.
Step 1: Check DNS Propagation
First, confirm that the DNS records are resolving to the correct IP addresses:
# Check the A record
dig +short example.com A
# Expected output: 65.21.184.101
# Check the AAAA record
dig +short example.com AAAA
# Expected output: 2a01:4f9:c012:a304::1
If you do not have dig installed, you can use nslookup instead:
nslookup example.com
Step 2: Test the HTTP Redirect
Once DNS has propagated, use curl to test that the redirect is working:
curl -I http://example.com
You should see a response like this:
HTTP/1.1 301 Moved Permanently
Location: https://www.example.com/
Also test the HTTPS redirect and path preservation:
# Test HTTPS redirect
curl -I https://example.com
# Test path preservation
curl -I https://example.com/about?ref=test
# Should redirect to: https://www.example.com/about?ref=test
Step 3: Test in a Browser
Open an incognito/private browsing window (to avoid cached redirects) and type your apex domain into the address bar. You should be redirected to the www version within a second or two. Check that the URL in the address bar shows www.example.com.
Troubleshooting Common Issues
If the redirect is not working after 30 minutes, work through the following checks:
DNS Records Not Propagating
DNS propagation can take up to 48 hours in rare cases. If dig +short example.com A does not return 65.21.184.101, your DNS changes have not propagated yet. You can speed things up by lowering the TTL (Time to Live) on your records to 300 seconds (5 minutes) before making changes. You can also check propagation status globally with online tools like whatsmydns.net.
SSL Certificate Error
The first time someone visits your apex domain over HTTPS, ApexToWWW provisions an SSL certificate from Let's Encrypt. This happens automatically but may take 30 to 60 seconds on the very first request. If you see a certificate error, wait a minute and try again. If the error persists after several minutes, double-check that your DNS records are correct and that no other A/AAAA records conflict with the ones you added.
Cloudflare Proxy Interfering
If you use Cloudflare as your DNS provider, the proxy (orange cloud) must be turned off for the apex domain A and AAAA records. Cloudflare's proxy intercepts traffic before it reaches the ApexToWWW server, which prevents the redirect from working. Set the records to DNS only (gray cloud).
Conflicting DNS Records
If you have multiple A or AAAA records for @, DNS may resolve to the wrong IP. Delete any old A/AAAA records for the apex domain that do not point to the ApexToWWW addresses. Keep your www CNAME or A record as-is since that is where your actual website is hosted.
Browser Caching Old Results
Browsers aggressively cache DNS results and redirects. If you previously visited your apex domain and it returned a different response, the browser may have cached that result. Clear your browser cache or test in an incognito/private window. You can also try a different browser or device to rule out caching.
Redirect Loop
If you see an "ERR_TOO_MANY_REDIRECTS" error, your www record may also be pointing back to the apex domain or to ApexToWWW. The www CNAME or A record should point to your actual hosting provider (e.g., your Netlify, Vercel, GitHub Pages, or web server address), not to 65.21.184.101. Only the apex domain records should use the ApexToWWW IP addresses.
Ready to Set Up Your Redirect?
ApexToWWW is free, requires no account, and takes less than two minutes to configure. Add two DNS records and your naked domain redirect is live.
Get Started Now