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 Théophile Louvart, 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.
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.
// 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.
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.
Confirm one hop
You want a single 301 to the canonical URL, then a 200. No extra jumps.
Confirm path preservation
The path and query string must survive. /pricing stays /pricing. ?ref=nav stays ?ref=nav.
Repeat on ten more URLs
Test a blog post, a file path, a 404 page, and anything linked from your home.
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.
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
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.
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.
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.
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.
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.
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.
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
- GuideCanonical tags: what they do and the mistakes that cost rankings
- GuideAlternate page with proper canonical tag: what Search Console means
- GuideBuild a redirect map: one old URL, one new URL, tested
- GuideTrailing slash: two URLs for one page unless you decide
- GuideHow to use Google Search Console in ten minutes a week
- Glossary301 redirect
- GuideDelete or redirect an old page: 301, 404 or 410
- Free toolRedirect checker