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.

The practical differences
Questionwww.example.comexample.com
Can it be a CNAME to a host?YesNot in plain DNS; needs ALIAS or flattening from your DNS host
Cookie scopeCan be kept to www onlyA cookie with Domain=example.com also reaches every subdomain
Typing and printFour characters longerShorter
SearchFine as the chosen version, with the other redirectingFine 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.

  1. Does your host ask you to point the domain at one of its names with a CNAME?
  2. Does your DNS host offer ALIAS, ANAME or CNAME flattening at the root?
  3. 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

  1. Answer the three questions about your DNS host, your site host and any other services on subdomains.
  2. The helper recommends www or the bare domain and says why.
  3. Copy the redirect rule for your server and the canonical tag for your pages.
  4. After it is live, test both versions with http and https; each should reach the chosen address in one hop.

Tips

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 rules generator, Redirect checker, Add a custom domain, DNS record types, Google Search Console guide.

Start for free or see all free tools. We.Inc is free to start, with no card needed. AI building is on paid plans from $20 a month.

More in Guides

We.Inc is an AI-powered website builder you can resell under your own brand. Launch a branded client dashboard, bill on Stripe Connect, and deliver AI-generated websites in minutes. White-label plans start at $99 a month for 25 client sites, with a 7-day free trial and no per-site fees.

Product

Who It's For

Features

Resources

Company

View Sitemap