Skip to content
AE DIGITAL
Server & DomainsBy 6 min read

www vs non-www: choosing your primary domain and setting up redirects correctly

www or non-www makes no difference to Google, as long as only one version exists. How to choose, which DNS limits matter and how to set up redirects, HTTPS and Search Console.

Article cover: the word “301” next to a glowing icon on a violet space background

www or non-www: does it matter to Google?

No. To Google, example.com and www.example.com are two separate hostnames that can serve the same content. Google Search Central's documentation simply asks you to pick one canonical URL and redirect the others. It states no preference between the two forms.

The real problem is a site that returns a 200 status on both versions, sometimes on http and https as well. That gives you up to four copies of the same site. Google chooses one as canonical, but backlinks, Search Console data and analytics get split, and sometimes the chosen version is not the one you wanted. Google describes redirects as a strong canonicalization signal, as is the rel="canonical" tag, while sitemap inclusion is a weak one. The signals stack, so use all of them consistently.

Technical limits: CNAME and the zone apex

The bare domain, example.com, is called the apex or root of the DNS zone. It always holds NS and SOA records, and often MX and TXT records for email and verification. RFC 1912 is explicit: a CNAME record is not allowed to coexist with any other data on the same name. So in standard DNS you cannot put a CNAME at the apex.

Why it matters

Many platforms and CDNs ask you to point your domain with a CNAME to one of their hostnames, so they can change IP addresses without you touching DNS. On www that is easy. At the apex you have three options:

  • A and AAAA records pointing to fixed IPs from the platform, if it provides them;
  • an ALIAS or ANAME record, if your DNS provider supports one;
  • Cloudflare's CNAME flattening, which resolves the CNAME and returns IP addresses directly while staying standards-compliant.

There is also a lesser-known argument for www: a cookie set with a Domain attribute on the root domain is also sent to subdomains. With the site on www it is easier to keep site cookies apart from subdomains such as static. or app..

Choosing the primary version

For a new site the choice is mostly cosmetic. For an existing one we follow this order:

  1. Which version is already indexed? Check Search Console or a site: query. If Google already shows www, keep it.
  2. Which version do backlinks and campaigns use? Business cards, email signatures, live ads.
  3. Does your platform handle the apex well? If hosting requires a CNAME and your DNS has no flattening or ALIAS, www saves you trouble.
  4. Brand preference: a short domain printed without www still works when the site lives on www, because the redirect handles the rest.

Switching versions on a site with years of history, without a technical reason, is work and risk for no gain.

301 redirects and HTTPS

Say you choose https://www.example.com. The other three variants must reach it in a single hop:

  • http://example.com to https://www.example.com
  • http://www.example.com to https://www.example.com
  • https://example.com to https://www.example.com

Common mistakes: chains of two or three redirects (http non-www, then https non-www, then https www), redirects that send everything to the home page instead of the equivalent page, and query parameters lost along the way. The path and query string must stay the same.

The certificate must cover both names

Someone typing https://example.com must receive a valid certificate before the redirect. If the certificate only covers www, the browser shows an error and the visitor never reaches the redirect. Google notes that invalid certificates and HTTPS-to-HTTP redirects push it to prefer the HTTP version. For renewals and certificate chains, see the guide on TLS certificates for ecommerce.

Setup on Shopify, Cloudflare and traditional hosting

Shopify

According to Shopify's manual connection guide, the root domain points to 23.227.38.65 with an A record (plus the AAAA record listed in the guide) and www uses a CNAME to shops.myshopify.com. Under Settings > Domains you choose the primary domain, and Shopify redirects the other connected domains to it. Nothing else is needed.

Cloudflare

If your DNS is on Cloudflare, set the redirect with a Redirect Rule: match https://example.com/*, target https://www.example.com/${1}, status 301 and the option to preserve the query string. The hostname being redirected needs a proxied DNS record, otherwise requests do not pass through Cloudflare and the rule never runs. Also switch on the automatic http to https redirect.

Apache or Nginx hosting

On Apache, in .htaccess, a condition RewriteCond %{HTTP_HOST} ^example\.com$ [NC] followed by RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]. On Nginx, a server block for example.com with return 301 https://www.example.com$request_uri;. On WordPress, also check that WordPress Address and Site Address under Settings > General use the chosen version. For a refresher on records and nameservers, see the technical guide to DNS, domains and hosting.

Search Console and other tools

In Search Console create a Domain property: it includes www and non-www, http and https, and is verified with a DNS TXT record. URL-prefix properties only cover the exact prefix you enter. Then align everything else with the chosen version:

  • the canonical tag on every page;
  • URLs in the XML sitemap and robots.txt;
  • internal links, menus and images with absolute URLs;
  • hreflang tags, if the site is multilingual;
  • final URLs in ads and product feeds;
  • GA4 data streams and allowed domains in consent tools.

Final checks

From a terminal, curl -sI http://example.com should return a 301 with Location: https://www.example.com/. Repeat with the other variants and with a deep path such as /products/shoe?colour=red: the target must keep path and parameters, in one hop. Check the certificate on both names in a browser and, after a few weeks, the Search Console Pages report: alternate pages with redirects should appear as such, with no growth in duplicates. If you are also changing hosting or platform at the same time, plan the steps like a zero-downtime migration. If you would rather have someone check DNS, redirects and certificates before touching production, get in touch.

Frequently asked questions

Does www affect rankings?

No. Google treats the two versions as different URLs for the same content and asks you to choose one as canonical. The problem only appears when both return a 200 status: signals and links are split between two copies of the site.

Can I switch versions on an indexed site?

Yes, with a 301 redirect from every old URL to its new equivalent, plus updated canonicals, sitemap and internal links. Seeing both versions in Search Console for a few weeks is normal. Only do it for a concrete technical reason.

Does the redirecting hostname need a certificate?

Yes. Someone typing https://example.com must get a valid certificate before being redirected to https://www.example.com. The certificate must cover both names, otherwise the browser shows an error before the redirect happens.

Is a 302 redirect good enough?

For a permanent change use 301 or 308. A 302 signals a temporary move; Google may eventually treat a long-standing 302 as permanent, but it sends a less clear signal about which version is primary.

Sources

  1. How to specify a canonical URL with rel=canonical and other methods — Google Search Central
  2. Add a website property to Search Console — Google Search Console Help
  3. RFC 1912: Common DNS Operational and Configuration Errors — RFC Editor
  4. Redirect from root to WWW — Cloudflare Docs
  5. CNAME flattening — Cloudflare Docs
  6. Connect your third-party domain to Shopify manually — Shopify Help Center

Related articles

Tell us what isn't working.

We reply within one business day with a first opinion and, if it makes sense, a quote.

Write to us