Redirect WWW to Apex Domain
Looking to redirect www.yourdomain.com → yourdomain.com instead of the other way around? This is the opposite direction from what ApexToWWW does — here's how to set it up natively on the platform you're using.
ApexToWWW only redirects apex → www, not the reverse. To redirect www → apex, your hosting platform (or CDN) needs to serve the apex directly — via ALIAS/ANAME, CNAME flattening, or native apex support — then apply a redirect rule on www. Jump to instructions for Cloudflare Pages, Vercel, Netlify, or any other host.
Should You Redirect WWW to Apex? Consider This First
Both directions are valid choices — Google treats apex and www as equally canonical-able, and there's no SEO penalty either way as long as the redirect is a proper 301. But the two directions have different technical trade-offs:
- WWW as canonical supports CNAME records (required by most CDNs and PaaS platforms), enables cookie isolation between subdomains, and is the path of least friction on hosts like Vercel, Netlify, GitHub Pages, and Heroku.
- Apex as canonical is shorter and feels more "native," but requires your DNS provider to support ALIAS/ANAME/CNAME flattening, or your host to resolve the apex directly — not all hosts or DNS providers support this.
For the full breakdown of trade-offs, see Apex Domain vs WWW: Which Should You Use? If you're set on apex as canonical, the instructions below cover the most common platforms.
Cloudflare Pages: Redirect WWW to Apex
Point the apex at your Cloudflare Pages project — CNAME flattening on @ to your-project.pages.dev, or an ALIAS/ANAME record if your DNS provider supports one — then add a Cloudflare Redirect Rule matching http.host eq "www.yourdomain.com" that 301s to https://yourdomain.com. On the legacy free plan, a Page Rule (www.yourdomain.com/* → https://yourdomain.com/$1, 301) does the same job.
Full walkthrough with a Worker-based alternative: Cloudflare Pages apex redirect guide — reverse direction section.
Vercel: Redirect WWW to Apex
Vercel handles this natively. Add both www.yourdomain.com and yourdomain.com in Settings → Domains, use the three-dot menu on the www entry to redirect it to the apex, and set the apex as primary. Or add a host-matched rule in next.config.js or vercel.json if you'd rather keep the rule in code.
Full walkthrough with working code snippets: Vercel apex redirect guide — reverse direction section.
Netlify: Redirect WWW to Apex
Netlify supports serving directly from the apex out of the box — it provides its own load-balancer IP for apex A records, so you don't need ALIAS/ANAME at all. In Site settings → Domain management → Custom domains, add both yourdomain.com and www.yourdomain.com, then use the "Set as primary domain" option on the apex entry. Netlify automatically 301-redirects the other variant for you — no separate redirect rule needed.
Any Other Host: Generic Approach
For platforms without a built-in www→apex toggle, you need two pieces:
- Serve the apex. Either your host resolves the apex directly (check their docs for apex/root domain support), or your DNS provider offers ALIAS/ANAME/CNAME flattening to point the apex at your host's target hostname.
- Redirect www to apex. If your DNS or CDN sits in front of requests (e.g., Cloudflare, even for a non-Cloudflare-hosted site), add a redirect rule there. If you run your own server, a two-line nginx config does it:
server {
listen 443 ssl;
server_name www.yourdomain.com;
return 301 https://yourdomain.com$request_uri;
}
This preserves the path and query string, exactly like a DNS-based redirect service would.
Frequently Asked Questions
How do I redirect www.yourdomain.com to yourdomain.com?
Point your apex domain at your host (natively on platforms like Netlify, or via ALIAS/ANAME/CNAME flattening elsewhere), then add a redirect rule that 301s www to the apex. The exact steps depend on your host — see the platform-specific instructions above for Cloudflare Pages, Vercel, and Netlify, or use a generic Cloudflare Redirect Rule / nginx config for any other host.
Does ApexToWWW redirect www to apex?
No. ApexToWWW only redirects apex to www (yourdomain.com to www.yourdomain.com), which is the more common and generally recommended direction since it keeps you on CNAME-based hosting. For the reverse direction, use your hosting platform's native redirect feature or a service like Cloudflare Redirect Rules.
Should I use apex or www as my canonical domain?
Both work. WWW is usually the safer default: it supports CNAME records required by most CDNs and hosting platforms, and enables cookie isolation between subdomains. Apex as canonical is shorter and works well if your DNS provider supports ALIAS/ANAME or your host resolves the apex natively. The important thing is picking one and 301-redirecting the other.
Will redirecting www to apex hurt my SEO?
No, as long as it's a proper HTTP 301 (permanent redirect). Google explicitly supports either apex or www as canonical — the redirect direction itself has no SEO penalty. What matters is consistency: pick one version and make sure every URL variant (http/https, www/apex) redirects to it.
Actually Want Apex → WWW Instead?
That's what ApexToWWW does — free, 2 DNS records, automatic SSL, no signup.
Get Started NowQuestions? Email hi@apextowww.com