# 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.

Updated 2026-09-14 · Source: https://porteur.ai/guides/www-vs-non-www

## 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.

> Use a 301, not a 302. Redirect every path one to one, not everything to the home page.

## 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.

```bash
# 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;
}
```

```js
// 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.

## Canonicals, internal links, and sitemaps

Set the rel=canonical tag on every page to the chosen host. If you pick https://www.example.com, the canonical on /pricing should be https://www.example.com/pricing.

Update internal links to the canonical host. Do not link some places to www and others to non-www. Keep it consistent in nav, footers, blog posts, and emails too.

Update your XML sitemap to list only canonical URLs. Submit it in Search Console. Keep only one sitemap location if you can, and remove stale ones later.

```js
// Next.js App Router: set canonical per page
export async function generateMetadata() {
  const base = new URL('https://www.example.com')
  return {
    metadataBase: base,
    alternates: { canonical: '/pricing' },
  }
}

// app/sitemap.ts should emit only canonical URLs

```

## 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.

```bash
# 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

### What is the difference between www and non-www?

They are different hosts. www.example.com and example.com are separate to Google and to browsers. You decide which one is canonical, then redirect the other to it on every path with a 301.

### Is it better to have www or not?

There is no ranking benefit either way. Pick the one you prefer to show users. If you use subdomains for an app or assets, www can help keep cookies scoped to the site only.

### Should I use the www prefix?

Use it if it fits your brand or cookie plan. Many companies use www for the site and app.example.com for the product. Many small sites use the apex. Both are fine when you redirect the other host and set canonicals.

### Do I need the Change of Address tool for www to non-www?

No. That tool is for moves between domains, for example example.com to example.org, and only when both properties are verified and the 301s are in place. For www vs non-www you just use 301 redirects, canonicals, and a Domain property.

### Will changing www to non-www hurt my SEO?

It should not if you do it cleanly. Keep one hop redirects, preserve every path, set canonicals and update internal links and the sitemap. Expect some crawl churn for a few weeks as Google recrawls and consolidates signals.

### How do I test if my redirects are correct?

Use a redirect checker on a sample of URLs. Look for one 301 to the canonical URL and a final 200. Confirm the path and query are preserved. Check http and https on both hosts.

## Read next

- [Canonical tags: what they do and the mistakes that cost rankings](https://porteur.ai/guides/canonical-tag): What a canonical tag does, when to use one, the mistakes that cost rankings, and how to check and fix canonicals on a small site.
- [Alternate page with proper canonical tag: what Search Console means](https://porteur.ai/guides/alternate-page-with-proper-canonical-tag): What this Search Console status means, when to ignore it, when it hides the wrong page, and the exact checks and fixes to set the right canonical.
- [Build a redirect map: one old URL, one new URL, tested](https://porteur.ai/guides/redirect-map): A practical redirect map: where to find old URLs, how to match them, store the table, apply 301s, and test every row for one hop and a 200.
- [Trailing slash: two URLs for one page unless you decide](https://porteur.ai/guides/trailing-slash-seo): Google sees /page and /page/ as different. Pick one form, redirect the other, and keep links and your sitemap consistent. Here is how to do it.
- [How to use Google Search Console in ten minutes a week](https://porteur.ai/guides/how-to-use-google-search-console): A quick weekly routine: set four filters, compare 28 days, check pages then queries, and fix three findings, without getting lost in noise.
- [301 redirect](https://porteur.ai/glossary/301-redirect): A 301 redirect is a permanent move. Use it to send users and bots to a new URL, keep signals, avoid chains, and choose 308 when methods must persist.

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: https://porteur.ai/
