DevSwitch.net

www or non-www: Picking One Domain and Making It Stick

The www vs non www choice comes down to cookies and DNS, not rankings. Learn which address to pick and how to enforce it everywhere.

Jay HoldenPublished ยท 5 min read
Two web address routes merging into a single secure browser window, showing www and non-www joined into one domain
Key takeaways The short version, before the details.
  1. Either form works for search, but serving both without a redirect does not.
  2. Cookie scope, DNS flexibility at the apex and shorter branding decide the choice.
  3. The redirect is only one step: certificates, canonicals, sitemaps and app settings must all agree.

www vs non www: which should you pick?

The www vs non www question has a short answer: either one is fine for search, but serving both without a redirect is not. Pick one hostname, send the other to it permanently, and use it everywhere.

The two addresses are separate hostnames. Left alone, example.com and www.example.com can both serve the same pages, splitting links, analytics and logins between them.

Does www vs non www SEO change rankings?

Neither form ranks better on its own. Search engines treat them as two URLs for the same page and choose one as canonical. Google's guide to consolidating duplicate URLs lists the signals it reads, including redirects, canonical tags and sitemaps. Your job is to make them all agree.

Apex domain vs www: what actually decides it?

The apex is the bare domain, also called the root. Three arguments separate it from www.

How does cookie scope work across subdomains?

A cookie with no Domain attribute stays on the exact host that set it. The trouble starts when you need to share one. On a bare domain, Domain=example.com reaches every subdomain, including a help desk or status page a vendor runs for you.

On a www site, a cookie scoped to www.example.com reaches that host and anything below it, but not app.example.com or static.example.com. The MDN Set-Cookie reference covers the exact rules.

Can you use a root domain CNAME?

Not in standard DNS. A name with a CNAME record cannot hold other records (RFC 1034), and the apex must hold SOA and NS records. So www can point at a CDN or platform hostname with a CNAME, while the apex normally uses fixed A and AAAA records.

Many DNS providers work around this with ALIAS, ANAME or CNAME flattening, which answer with addresses from the target. Support varies, so check yours first.

Is a shorter domain better for branding?

The bare domain is shorter on business cards, in ads and when read aloud. Visitors who type the other form still arrive, because the redirect catches them.

Your situationBetter fit
Cookies must stay away from other subdomainswww
You point at a CDN hostname and your DNS has no flatteningwww
Short address matters and you have few subdomainsNon-www
The site is already live and none of this appliesKeep what your links already use

Where must you apply your canonical domain?

A redirect alone leaves your own site pointing at the wrong host. Apply the choice in each of these places:

  • DNS: both names must resolve, or the redirect never runs.
  • TLS certificate: it must cover both names, because the browser checks it before any redirect. If yours has lapsed, renew the SSL certificate first.
  • Server redirect: a permanent one for every path. The 301 vs 302 guide explains why the code matters.
  • Canonical tags and XML sitemap: only URLs on the chosen host.
  • Internal links: templates, menus, image paths and email footers.
  • App settings: OAuth callback URLs, CORS allowed origins, webhooks and cookie Domain values.
  • Search Console: a Domain property covers both hostnames. Google retired its preferred domain setting, so your redirect and canonicals carry that message now.

What should you watch after switching?

Check the redirect by hand first. You want one 301 whose Location header names the final host:

curl -I http://www.example.com/some-page

Then spend the first week on these:

  • Every URL, not just the home page: pull your list with the Sitemap Extractor and run it through curl.
  • Chains and loops: behind a proxy that reaches your server over plain HTTP, a Force HTTPS rule can loop until the browser shows ERR_TOO_MANY_REDIRECTS.
  • Logged-out users: host-only cookies do not follow the move, so expect people to sign in again.
  • Search Console: old-host URLs should drift out of the index gradually. Google's site move guide advises keeping redirects for at least a year.
  • Stale results: browsers cache 301s, so test in a private window.

How do you redirect www to non www?

On Apache, the DevSwitch .htaccess Generator writes this rule for you. Enter your domain, then switch on Remove www or Add www; the two switches exclude each other. With Force HTTPS also on, both fixes merge into a single redirect instead of two chained ones:

# Force HTTPS and remove www in one redirect
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
# Force HTTPS and add www in one redirect
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
Both rules always target https://, even with Force HTTPS off, so HTTPS must work before you upload the file. If the domain field is empty, the rule is left out and the tool warns you.

Already have a file? Load it and the tool switches on the options it recognizes, but your other lines do not come back out, so merge those by hand. Nginx ignores .htaccess files, so there the redirect goes in the server block.

Two domain paths merging into one secure address through a redirect
.htaccess Generator

Make one domain stick on Apache

Enter your domain, choose Add www or Remove www, and get the redirect written against it.

Generate the redirectCopy it or download the file

Frequently asked questions

No. Neither form has a ranking advantage on its own. What can hurt is serving both, because signals split until a search engine picks a canonical for you. Choose one hostname, redirect the other, and make your canonical tags, sitemap and internal links agree with it.

Mostly DNS and cookies. A www hostname can be a CNAME pointing at a CDN, so traffic can move without touching apex records, and cookies scoped to www stay away from sibling subdomains. With many subdomains and vendors, that separation is worth a slightly longer address.

A cookie set with Domain=example.com goes to every subdomain, including ones run by vendors. Without a Domain attribute it stays on the exact host, so the problem only appears when you need a shared cookie. A www main host lets you scope that cookie more narrowly.

Not if the move is done properly. Use permanent redirects for every URL, update canonicals, the sitemap and internal links, and keep the redirects in place. Expect some fluctuation while search engines recrawl. Real losses usually come from loops, broken paths or a certificate that misses one hostname.

Both names should resolve, because people type either one, but only one should answer with content. The other should return a permanent redirect. Two live copies create duplicate URLs, split links and analytics, and leave logged-in visitors with separate cookies on each host.