www vs non-www: pick one and redirect the other correctly
Neither www nor non-www ranks better. Pick one host, 301 the other in one hop, and align DNS, HSTS and Search Console so only one copy of your site exists.
LLaunchScaler·Published ·8 min read
Neither www nor non-www ranks better: Google treats www.example.com and example.com as two URLs for the same content and indexes whichever one your signals point to. What costs you is serving both. Pick one host, give both a DNS record, redirect the other permanently in a single hop, and make your canonical tags, sitemap and HSTS policy agree.
The choice itself is about infrastructure, not search. The setup is where sites go wrong.
Is www or non-www better for SEO?
Neither is better. Google's documentation treats https://www.example.com and https://example.com as duplicate URLs and asks you to pick one and redirect the others to it. It picks a canonical itself if you don't, and nothing in its documentation gives either form a ranking advantage. The search question is only whether you serve one host or two.
Google even retired the Search Console setting that used to handle this. When it removed the "preferred domain" option in 2019, it said that when its systems see the same content on several URLs, it picks one as canonical, and that you state your preference with rel="canonical", a sitemap, or 301 redirects for retired URLs.
The reasons to prefer one host are technical:
Consideration
www (www.example.com)
Non-www (example.com)
Ranking
No difference
Questions, answered
What people ask about this
01
Is www or non-www better for SEO?
Neither. Google treats www.example.com and example.com as two URLs for the same content and picks one as canonical, and nothing in its documentation gives either host a ranking advantage. What matters is that one redirects to the other.
A CNAME is allowed, so the host can point at a CDN name
The DNS spec forbids a CNAME at the apex, so it needs an A record or a provider-specific alias
Host guidance
Vercel recommends www as the primary, with the apex redirecting to it
Works, and Vercel supports it with Anycast on an A record
Length in links
Four characters longer
Shorter
Existing links
Keep it if most backlinks and indexed URLs use www
Keep it if most use the bare domain
If your site already ranks, keep the host Google shows today. Switching means every indexed URL moves through a redirect, which works but buys nothing.
What happens if both hosts answer with a 200?
Google sees two copies of every page and has to pick one. With no redirect, it clusters www.example.com/pricing and example.com/pricing as duplicates and chooses a canonical itself, using whatever signals it has: your canonical tags, the host your sitemap lists, the host your internal links use. If those disagree, it can pick the host you don't use.
The symptoms show up in Search Console rather than in rankings. The Page indexing report fills with "Duplicate without user-selected canonical" rows when no canonical tag is set, or "Duplicate, Google chose different canonical than user" when your tag names one host and Google indexes the other. Links other sites give you are also split between two addresses until Google consolidates them. A permanent redirect removes the choice: only one host ever returns a page.
How do you set up DNS for both hosts?
Give both hosts a DNS record, even the one you will redirect. If www.example.com has no record, anyone who types it or follows an old link gets a DNS error before your redirect can run. The apex takes an A record, and www usually takes a CNAME to your host.
On Vercel, for example, the apex uses an A record and a subdomain such as www uses the CNAME value shown on the project's domain card. The docs explain why they suggest www as the primary: the DNS spec forbids CNAME records on apex domains, and a CNAME lets the host steer traffic without hard-coding an IP address. Adding an apex domain to a Vercel project prompts you to add its www counterpart.
Then pick where the redirect lives. It belongs at the host or CDN, before your application runs:
Add both example.com and www.example.com to your host.
Mark one as primary.
Set the other to redirect to it permanently. On Vercel, open Project Settings, then Domains, select Edit on the domain to redirect from, and choose the target in the Redirect to dropdown.
Make sure both hosts have a valid TLS certificate, because an https://www request has to complete the handshake before it can receive the redirect.
Vercel notes that it will try to redirect between the two forms automatically, but recommends adding the redirect explicitly.
How should the redirect work?
The non-canonical host should answer every path with a permanent redirect (301 or 308) straight to the same path on the canonical host, over https. https://www.example.com/pricing?plan=pro should go to https://example.com/pricing?plan=pro in one response, keeping the path and query string.
Three rules keep it clean:
Permanent, not temporary. Google treats 301 and 308 as permanent redirects and uses them as a signal that the target should be canonical. A 302 or 307 tells it the move is temporary.
Path-preserving. A redirect that sends every www URL to the homepage throws away deep links: anyone following a link to /pricing lands on the homepage instead, and Google loses the one-to-one mapping between old and new URLs.
Server-side. Google recommends a server-side redirect whenever possible; a JavaScript redirect only works once the page renders.
Why must the redirect be one hop?
Each hop is a separate request for browsers and crawlers. Google's crawlers follow up to 10 redirect hops, and its crawl budget guide says to avoid long redirect chains because they hurt crawling. The common mistake chains the protocol and host redirects: http://www goes to https://www, which then goes to https://. Send every variant straight to the final URL instead.
Chains usually come from two layers each doing one job: the CDN upgrades http to https without changing the host, then the app or host changes the host. Fix it by writing one rule that matches every non-canonical combination of protocol and host and targets the final URL. Add the trailing slash rule to the same layer, so http://www.example.com/pricing/ does not become three hops; the trailing slash guide shows how. The HTTP to HTTPS redirect guide covers the protocol side in detail.
One exception applies if you plan to submit your domain to the HSTS preload list. Its requirements include redirecting from HTTP to HTTPS on the same host first. For a site whose canonical host is www, that means http://example.com must go to https://example.com before going to https://www.example.com, so that one request takes two hops by design.
Does HSTS on www cover the non-www domain?
No. The includeSubDomains directive only extends a policy downward, to subdomains of the host that sent the header. A policy set on example.com with includeSubDomains covers www.example.com. A policy set on www.example.com covers login.www.example.com, never example.com.
MDN's reference gives the exact case: if example.com sends HSTS with includeSubDomains but all links go directly to www.example.com, the browser never sees the apex's header. So:
Send Strict-Transport-Security from both hosts, including on the redirect response from the non-canonical one. Browsers ignore the header when it arrives over plain http, so it only counts on https responses.
Put includeSubDomains on the apex's header if every subdomain you run serves HTTPS.
For preloading, the apex must send max-age of at least 31536000 with both includeSubDomains and preload, and the HSTS preload site says a redirect from your HTTPS site must still carry the header.
Don't add preload casually. The HSTS preload site warns that removal "tends to be slow and painful" and that preloading covers every subdomain, including internal ones. The HSTS header guide covers the rollout order.
How does Search Console handle www and non-www?
A Domain property covers both. Adding example.com as a Domain property includes www.example.com, example.com and every other subdomain, on both http and https, and Search Console creates example.com even if you type the www form. It is the property that shows whether Google is still indexing the host you redirect.
If you use a URL-prefix property, it must name the host you actually serve. A property for https://www.example.com/ on a site that serves https://example.com/ holds almost no data, because Google indexes the host that answers 200, not the one that redirects. The Domain property vs URL-prefix guide explains when to add each.
After the redirect is live, the redirected host's URLs move into the Page indexing report under "Page with redirect". That is expected and needs no action as long as your sitemap and internal links use the canonical host.
How do you check the redirect with curl?
Request every combination of protocol and host without following redirects. Three of the four should return a single 301 or 308 whose location is the final canonical URL, and the canonical https:// host should return 200.
For a non-www site, the first three should each show 301 or 308 and location: https://example.com/pricing, and the last should show 200. If any location points at an intermediate URL, follow it with curl -sIL to see the chain. Then confirm the pieces that can't be seen in a status line:
The canonical tag on the page names the canonical host.
Every <loc> in the sitemap uses the canonical host.
Internal links, including absolute links in emails and Open Graph tags, use the canonical host.
The Strict-Transport-Security header appears on the https responses from both hosts.
Check every host variant at once
Run the free scan on LaunchScaler with just your address and no account. It runs 156 checks across 6 of its 7 categories at no cost, and its checks cover the parts of this setup that tend to drift: redirect chains that take more than one hop to reach the final page, a canonical tag that is missing or points at another URL, a sitemap that lists redirecting or non-canonical URLs, and the HSTS header in its security checks.
Yes. Both hosts must resolve, or visitors and links that use the other form hit an error instead of your redirect. The apex usually takes an A record and www usually takes a CNAME.
03
Should the www redirect be a 301 or a 308?
Either works. Google treats 301 and 308 as permanent redirects and uses them as a signal that the target should be canonical. What matters more is that it is permanent and takes one hop.
04
Does HSTS on www cover the non-www domain?
No. includeSubDomains only extends a policy downward, to subdomains of the host that sent it. A policy on example.com with includeSubDomains covers www.example.com, but a policy on www.example.com never covers example.com.
05
Do I need two Search Console properties for www and non-www?
No. A Domain property for example.com includes both hosts on both protocols. Add a URL-prefix property for your chosen host only if you want reports limited to it.
Alternate page with proper canonical tag means Google honoured your canonical and indexed that URL. It only hurts when a template canonicalises every page.
Blocked by robots.txt means a rule stops Googlebot fetching the URL. Find the group Googlebot obeys and the longest matching rule, then edit that line.