www vs non-www: Pick One and Redirect the Other
Either works for search and visitors, as long as you choose one and permanently redirect the other to it. The real differences are technical: a www name can be a CNAME pointing at your host, while the bare domain usually cannot, and cookies set on the bare domain reach every subdomain. Consistency matters far more than the choice.
| Question | www.example.com | example.com |
|---|---|---|
| Can it be a CNAME to a host? | Yes | Not in plain DNS; needs ALIAS or flattening from your DNS host |
| Cookie scope | Can be kept to www only | A cookie with Domain=example.com also reaches every subdomain |
| Typing and print | Four characters longer | Shorter |
| Search | Fine as the chosen version, with the other redirecting | Fine as the chosen version, with the other redirecting |
Updated
Many small business sites answer on both addresses without meaning to, which splits links and leaves search engines to guess which is the real one. Fixing it takes one decision and two small changes: a permanent redirect from the version you drop, and a canonical tag on every page naming the version you keep. Answer the questions below for a recommendation and the code to apply it.
Which should you choose?
Answer three questions. The recommendation and code update as you change an answer.
- Does your host ask you to point the domain at one of its names with a CNAME?
- Does your DNS host offer ALIAS, ANAME or CNAME flattening at the root?
- Do you run other things on subdomains, such as shop. or app., that should not receive your main site's cookies?
Redirect and canonical code
Nginx: send the bare domain to www
One server block catches the dropped name on both ports and sends everything to the chosen one with a 301.
server {
listen 80;
listen 443 ssl;
server_name example.com;
return 301 https://www.example.com$request_uri;
}Canonical tag on each page
Every page names its own address on the chosen version, which backs up the redirect.
<link rel="canonical" href="https://www.example.com/services/">Typical DNS for a www site
The www name is a CNAME to the host; the bare domain keeps an A record pointing at whatever performs the redirect.
www.example.com. 3600 IN CNAME sites.host-example.net.
example.com. 3600 IN A 192.0.2.80
Why the bare domain is harder to point at a host
Hosting platforms often ask you to point your domain at a name they control with a CNAME, so they can move servers without you changing DNS. That is easy for www. At the bare domain, plain DNS only allows A and AAAA records with fixed addresses.
Cloudflare's documentation describes CNAME flattening as a way to use a CNAME at the zone apex: it follows the chain and returns the final IP address instead. Other DNS hosts sell the same idea as ALIAS or ANAME records.
Doing the switch without losing traffic
Add the redirect and canonical tag on the same day, then resubmit the sitemap with the chosen version. Old links keep working because the redirect forwards them, path and all.
Watch the Pages report in Search Console for a few weeks. Pages on the dropped version should drop out as redirects while the chosen version takes their place.
How it works
- Answer the three questions about your DNS host, your site host and any other services on subdomains.
- The helper recommends www or the bare domain and says why.
- Copy the redirect rule for your server and the canonical tag for your pages.
- After it is live, test both versions with http and https; each should reach the chosen address in one hop.
Tips
- If your site has been live for a while, keep the version most of your links already use and redirect the other.
- Update the address in Google Search Console, your sitemap, your Google Business Profile and your social profiles to match.
- Keep internal links pointing at the chosen version, so visitors and crawlers never pass through the redirect.
- Both names still need DNS records, or the redirect has nothing to answer with.
- Your TLS certificate must cover both names, since the redirect runs after the secure connection is made.
Frequently asked questions
Is www or non-www better for SEO?
Google's guidance on duplicate URLs is about picking one version, not about which one. What hurts is serving the same pages on both, because Google then has to pick a canonical. Its documentation calls redirects and rel=canonical strong signals, so use both to tell it which one you chose.
Why can my bare domain not be a CNAME?
The DNS standard says no other data should sit at a name that holds a CNAME. The bare domain must carry SOA and NS records, so a CNAME there breaks that rule. Some DNS hosts offer ALIAS records or CNAME flattening to get the same effect.
Do cookies behave differently on www?
A cookie set without a Domain attribute stays with the exact host that set it. A cookie set with Domain=example.com is sent to example.com and all its subdomains, such as shop.example.com, which can leak data or add weight to every request there.
Should I use a 301 or 302 between them?
A 301 or 308, because the choice is permanent. Google uses a permanent redirect as a signal that the target should be canonical, and a temporary one does not carry that signal.
My site builder handles the domain. Do I need to do anything?
Check the settings for a primary domain option. Most hosted builders let you connect both names and mark one as primary, then redirect the other for you. Test both addresses in a browser to confirm.
Related: Domain forwarding, Redirect checker, Add a custom domain, DNS record types, Google Search Console guide.
Build your site free or see all free tools. On We.Inc you can build your site free, with no card and no trial needed to start. AI building is on paid plans from $19 a month.
More in Guides
- YAML Comments: How to Comment, and Comment Out, YAML
- YAML Front Matter: Metadata at the Top of a Markdown File
- YAML Multiline Strings: | and >, Explained with a Live Preview
- YAML vs JSON: Which One, and Why
- Your Connection Is Not Private: Causes and Fixes
- 400 Bad Request: What Was Wrong With the Request
- 401 vs 403: Pick the Right Status for a Refused Request
- 403 Forbidden: Why the Server Refuses and How to Fix It
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App