www or non-www: pick one, redirect the other

Pick one host: www or non-www. Redirect the other on every path with a 301. There is no ranking benefit either way. You do it to avoid split signals and messy links. This guide shows what to change and how to check it.

By , founder of Porteur · Updated 14 September 2026 · Markdown

The short answer

Google treats www.example.com and example.com as different hosts. Pick one as your canonical host. Redirect the other with a 301 on every path.

There is no SEO ranking difference between www and non-www. The win is consistency. Links, crawl, and signals consolidate to one set of URLs.

How to choose: www or non-www

Choose the one you prefer to show users. Most brands can pick either. Keep it simple and stick to it everywhere.

One technical point can decide it. Cookies and subdomains. If you use subdomains like app.example.com or static.example.com, www can help keep cookies scoped to www only. That avoids sending session cookies to assets or other apps by mistake.

If you do not run subdomains, pick the form you like. Many SaaS pick app.example.com for the product and www.example.com for the site. Many small sites run on the apex with no subdomains. Both are fine.

Redirect setup: every path, one hop, 301

Redirect the non-canonical host to the canonical host on every path. /pricing to /pricing, /blog/post to /blog/post. Do not add or remove slashes here. Keep query strings when present.

# nginx: redirect non-www to www
server {
  listen 80;
  server_name example.com;
  return 301 https://www.example.com$request_uri;
}

# nginx: redirect www to non-www
server {
  listen 80;
  server_name www.example.com;
  return 301 https://example.com$request_uri;
}
// Next.js (next.config.js): redirect non-www to www
module.exports = {
  async redirects() {
    return [
      {
        source: '/:path*',
        has: [{ type: 'host', value: 'example.com' }],
        destination: 'https://www.example.com/:path*',
        permanent: true,
      },
    ]
  },
}

Apply the rule at the edge or the web server. Aim for one hop only. For example, http://example.com/page to https://www.example.com/page in a single 301, not a chain through http://www.

Search Console: verify the lot with a Domain property

Verify a Domain property for example.com in Search Console. It covers http, https, www and non-www in one place. You see data and issues across hosts.

Use the URL Inspection tool on a sample page. Check the indexed URL uses the host you chose. If not, fix canonicals and links, and wait for a recrawl.

You do not use the Change of Address tool for www to non-www. That tool is for domain-level moves only, for example example.com to example.co.uk. It does not apply to path-only changes either as of 2026.

Test your redirects and fix chains

Check a list of real URLs. Include the home page, a product page like /pricing, a guide like /guides/getting-started, and a 404 like /does-not-exist. Test both hosts. Use a redirect checker.

  1. Request the non-canonical host

    Open http and https on both www and non-www for one URL. Note the final URL and the status.

  2. Confirm one hop

    You want a single 301 to the canonical URL, then a 200. No extra jumps.

  3. Confirm path preservation

    The path and query string must survive. /pricing stays /pricing. ?ref=nav stays ?ref=nav.

  4. Repeat on ten more URLs

    Test a blog post, a file path, a 404 page, and anything linked from your home.

  5. Update rules and retest

    Fix any chain or wrong path. Retest until all finish with one 200.

A fixed site feels boring in the trace. http://example.com/pricing goes straight to https://www.example.com/pricing with one 301, every time, for every path.

Trailing slash and HTTPS: keep rules simple

/page and /page/ are different URLs to Google. Pick one form. Redirect the other to it. Keep your internal links in that form. The root / is the exception.

HTTP to HTTPS is a site move in Google’s terms. Redirect every URL to its HTTPS twin in one hop. Update canonicals, sitemaps, hreflang and internal links to HTTPS. Avoid mixed content. Consider HSTS once all is clean.

Avoid chains between these rules. Combine host, protocol and slash choices into one redirect. For example, http://example.com/page, http://www.example.com/page, and https://example.com/page all end at https://www.example.com/page in one step.

# nginx: combine HTTPS + www + trailing slash
server {
  listen 80;
  listen ssl;  # 443 is the standard HTTPS port
  server_name example.com;
  return 301 https://www.example.com$request_uri;
}

# optional: enforce trailing slash for directories in app/router

Ports 80 and 443 are the standard HTTP and HTTPS ports, typical defaults, not measured.

Cookies and subdomains: keep scope tight

Cookies set on example.com are sent to all subdomains. Cookies set on www.example.com are not sent to app.example.com or static.example.com. This is why many teams choose www for the site when they also run app.example.com.

  • If you use a separate app subdomain, consider www for the marketing site to keep cookies out of the app and assets.
  • If you serve assets from a subdomain, keep asset hosts cookie free. For example, set cookies at www.example.com, not at example.com.
  • If you keep the site on the apex, audit cookies. Avoid setting cookies on example.com unless you need them across subdomains.

Check Set-Cookie headers in your app and CDN. Make sure the Domain attribute matches your plan. Test a page on www and a page on app with your browser dev tools. Confirm you do not send marketing cookies to the app or to assets.

Rollout plan for a live site

Plan the switch. Update redirects, canonicals, internal links, sitemaps and robots.txt at the same time. Deploy in a low traffic window if you can. Have a simple rollback: remove the redirect rule and revert the canonical if you must.

Crawl your site first. Export a list of current URLs. Check that your redirect catches each one. Keep a two-column redirect map in your repository so the rule is explicit and reviewable.

After deploy, test with a redirect checker and Search Console. Inspect a few URLs. Watch the Coverage and Performance reports over the next weeks. Expect normal crawl churn. Rankings should stay steady if you kept one hop and one target per URL.

Worked example: redirect www to non-www

You choose non-www. Your old URLs are on www. You want https://example.com everywhere.

  • Redirect https://www.example.com/:path* to https://example.com/:path* with a 301.
  • Set rel=canonical to https://example.com/... on all pages.
  • Update internal links in nav, footer and content to https://example.com.
  • Update your XML sitemap to list https://example.com URLs only.
  • Verify a Domain property in Search Console, and submit the new sitemap.
  • Test http and https on www and non-www for /, /pricing, /guides/getting-started, and a 404 path.

A fixed trace for /pricing looks like this: http://www.example.com/pricing to https://example.com/pricing with one 301, then a 200. No extra hops. Canonical points to https://example.com/pricing. The sitemap lists that URL only.

Questions

Sources

Check my site, free

Check your host and path rules in about thirty seconds: paste a URL and see which host resolves, whether your 301s are one hop, and three findings you can fix first with Porteur.

  • Free check, no card
  • Read-only, your own accounts
  • Readable by your agent

Read next