Skip to main content
Guide 7 min read

www vs non-www: How to Pick One and Redirect Correctly

Type your domain with www and the site loads. Drop the www and it loads too. Sounds great, right? Not quite. To Google, those are two different addresses, and if both stay live you split links, signals and crawl effort between two copies of one site. The www vs non www decision looks like a style choice. It’s a setup choice with real SEO consequences.

This guide explains the difference between the two, how to pick one and how to redirect the other so every visitor lands in the same place. You’ll get server examples for Apache and Nginx, a list of common mistakes and a checklist you can follow today.

What www and non www actually mean

Your domain, like example.com, is the root. Add www and you get www.example.com, which is a subdomain of that root. The version without www goes by a few names: the root domain, the apex domain or the naked domain.

Both can serve the same pages. But browsers and search engines treat them as separate hosts. Cookies, certificates and robots.txt files all belong to one host or the other, and that’s why this choice reaches further than it first appears.

Does it matter for SEO?

Short answer: neither version ranks better. Google has no favorite. What hurts is serving both. When both versions load, links split between them, Google has to guess which one to index and you can end up with duplicates. Pick one, redirect the other and the problem disappears.

Consistency is the whole game. A site that uses www everywhere beats a site that mixes both, no matter which one it chooses.

How to pick the one that fits

Ask yourself these questions:

  • Which version already has links and rankings? If your site has been live for years, keep the version Google already indexes. Switching adds risk and gives you nothing back.
  • What does your DNS provider support? Under the DNS rules, a root domain can’t hold a CNAME record. Many providers offer a workaround called ALIAS, ANAME or CNAME flattening. If yours doesn’t, www is the easier road.
  • Do you use a CDN? A www address works with CNAME based setups, which gives you more control over traffic.
  • Do cookies matter? A www site lets you scope cookies to that host and keep other subdomains clean. A root domain makes sharing cookies with every subdomain easier, which can help or hurt.
  • What do you like? Non www is shorter and looks cleaner. www still looks familiar to many visitors.

Starting fresh with no strong pull either way? Pick non www if your host supports it, or www if you want the DNS flexibility. Both work. Just don’t run both.

Set up DNS and certificates for both

A redirect only works if both versions reach your server. Point the root domain to your host with an A record, or the ALIAS style record your provider offers. Point www with a CNAME to the root or to your host.

If one of them doesn’t resolve, visitors who type that version see an error and never reach the redirect. The same goes for HTTPS. Your certificate has to cover both names. Without that, browsers show a security warning before the redirect gets a chance to run.

How to redirect the right way

Four rules cover it:

  • Use a 301 redirect, because your choice is permanent. Our guide on 301 vs 302 redirects explains why.
  • Cover all four versions: HTTP and HTTPS, each with and without www. All four must end on one final address.
  • Send each one in a single hop. If the HTTP root goes to the HTTPS root and then to the HTTPS www address, that’s a chain. Write the rule so it jumps straight to the end.
  • Keep the path and the query string. A visitor to a pricing page with a plan in the address should land on that same page, not on your homepage.

Here’s an Apache rule that sends the root domain to www:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

And the Nginx version, placed in its own server block:

server {
    listen 443 ssl;
    server_name example.com;
    return 301 https://www.example.com$request_uri;
}

Going the other way, from www to the root domain, just swap the names. The Nginx block also needs your certificate lines, and a matching block on port 80 handles plain HTTP. Not sure your host pattern matches? Test it in our regex tester first.

Not on your own server? Most hosts, Cloudflare and CMS tools have a redirect rule or a domain setting. WordPress stores your choice in its Site Address, so set that to match. If your CMS says www and your server says non www, you create a loop. Our guide on fixing a redirect loop shows how to break it.

Make every signal agree

A redirect is the strongest signal, but it isn’t the only one. Line up the rest so Google never sees mixed messages:

  • Canonical tags on every page should use your chosen version.
  • Internal links should point straight to the final address, not through a redirect.
  • Your sitemap should list only final URLs. Rebuild it with our sitemap generator.
  • Your robots.txt file should point to that sitemap. Our robots.txt generator builds the file.
  • Social tags like og:url should match too. Our Open Graph generator makes them in a minute.
  • In Search Console, add a domain property so you see both versions in one place. The old preferred domain setting is gone, so redirects and canonical tags do that job now.

Mistakes that cause trouble

These slips cause most of the damage:

  • Using a 302 for a permanent choice. Google may keep the wrong version in its index.
  • Building redirect chains. Each extra hop slows the page. Our guide on debugging redirect chains shows how to find and flatten them.
  • Creating a loop because the CMS and the server disagree.
  • Sending every old URL to the homepage instead of the matching page.
  • Skipping the certificate for the version you redirect away from.
  • Pointing DNS for only one version.
  • Leaving internal links on the old version, so every click takes a detour.
  • Testing in one browser only. Browsers cache 301 redirects hard, so use a private window or a checker.

Test all four versions

Run each of these through our redirect checker: the HTTP root, the HTTP www address, the HTTPS root and the HTTPS www address. The three that aren’t your final address should each show one 301 hop and end on the final address with a 200 status. The final address itself should answer 200 with no redirect at all.

Test a deep page too, like a blog post with a query string. If the path or the query disappears, your rule drops it. Edited a config file along the way? Compare the old and new versions with our text diff checker to catch a stray character.

A checklist for the switch

Work through these steps in order:

  1. Pick one version, and keep the one Google already indexes if your site is old.
  2. Point DNS for both versions at your host.
  3. Install a certificate that covers both names.
  4. Set up 301 redirects from the other three versions to the final address, in one hop each.
  5. Update your CMS site address to match.
  6. Update canonical tags, internal links, your sitemap and social tags.
  7. Test all four versions and a deep page with a redirect checker.
  8. Add a domain property in Search Console and watch for errors over the next few weeks.

The short version

Neither www nor non www ranks better, but serving both splits your signals. Pick one, keep the version Google already knows, and send the other three versions to it with single hop 301 redirects. Make sure DNS and your certificate cover both names, then line up your canonical tags, links and sitemap.

Type all four versions of your domain into a redirect checker today. If each one lands on the same address, you’re done.

Free browser based tools on Black Claaw to trace redirects, test host patterns, rebuild sitemaps and keep your signals in line.

View all tools

Advertisement