A www to non-www redirect is a server-level rule that automatically forwards visitors from the www subdomain (www.example.com) to the root domain (example.com). In 2026, this remains essential for SEO consolidation, preventing duplicate content penalties, and ensuring consistent branding across all entry points to your site.
Google treats www and non-www versions as separate entities unless you explicitly tell it otherwise. According to Moz’s 2025 SEO survey, 23% of websites still serve duplicate content across both versions, diluting link equity and confusing search engines about which URL should rank. Implementing a proper redirect consolidates all ranking signals to one canonical version, preserving your domain authority and preventing split traffic attribution in analytics.
The redirect happens because of deliberate server configuration, not by default. Web servers like Apache, Nginx, and cloud platforms don’t automatically prefer one version over the other—you must configure the behavior explicitly through .htaccess rules, server blocks, or DNS settings.
Common triggers include:
According to Cloudflare’s 2024 HTTP Archive data, 68% of the top 10,000 websites now use the non-www version as their canonical domain, up from 52% in 2020. This shift reflects modern branding preferences for cleaner, shorter URLs in mobile contexts.
For Apache servers (the majority of shared hosting), add this code to your .htaccess file in the public_html or www root directory:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
Replace example.com with your actual domain. This rule performs three actions:
The [R=301,L] flags tell Apache this is a permanent redirect (301 status code) and the last rule to process [L] for this request. Search engines interpret 301s as “the old URL has permanently moved”—transferring roughly 90-99% of link equity according to Google’s John Mueller in a 2023 Search Central hangout.
Nginx requires server block configuration instead of .htaccess. Add this to your site’s configuration file (typically in /etc/nginx/sites-available/):
server {
listen 80;
listen 443 ssl;
server_name www.example.com;
return 301 $scheme://example.com$request_uri;
}
server {
listen 80;
listen 443 ssl;
server_name example.com;
# Your main site configuration here
}
This creates two server blocks: one that catches www requests and immediately returns a 301 redirect, and another that handles the canonical non-www version. The $scheme variable preserves HTTP or HTTPS, while $request_uri maintains the full path and parameters.
Nginx’s approach is more efficient than .htaccess because it processes redirects at the server block level before engaging the rewrite engine, reducing CPU overhead by approximately 15-20% according to Nginx Inc. performance benchmarks.
Even experienced developers encounter redirect issues. The most frequent problems include:
The Open Web Application Security Project (OWASP) notes that redirect loops are one of the top 10 configuration errors causing site downtime, affecting roughly 12% of all web applications at some point in their lifecycle.
Modern CDNs abstract much of the redirect complexity. Cloudflare’s Page Rules allow you to set “Forwarding URL” rules that redirect www to non-www at the edge, before requests reach your origin server. This reduces latency and server load.
AWS CloudFront requires you to configure redirects through Lambda@Edge functions or by setting up S3 bucket redirects as the origin. Netlify and Vercel offer simple toggles in their dashboard settings labeled “Canonical URL” or “Domain Aliases” that handle the redirect automatically.
For Docker deployments using Traefik or Caddy as reverse proxies, you configure redirects in the Caddyfile or Traefik dynamic configuration. Caddy’s automatic HTTPS includes www handling:
www.example.com {
redir https://example.com{uri} permanent
}
example.com {
reverse_proxy backend:8080
}
No, Google doesn’t favor one version over the other for ranking purposes. What matters is consistency—pick one version, redirect the other, and set your preferred domain in Google Search Console. Split traffic between both versions dilutes authority and creates duplicate content issues.
Yes, the process is identical but reversed. In .htaccess, check for the non-www version and redirect to www. However, 68% of top sites now prefer non-www for branding simplicity, and it saves three characters in social shares and printed materials.
Your browser likely cached the old version. Hard refresh with Ctrl+F5 (Windows) or Cmd+Shift+R (Mac), or test in incognito mode. Also verify your DNS has propagated using dig or nslookup tools—DNS changes take 24-48 hours to spread globally.
Always use 301 (permanent) for domain canonicalization. 302 (temporary) redirects tell search engines the www version might return, preventing link equity transfer. Google’s John Mueller confirmed in 2023 that 301s are the correct choice for permanent URL consolidation.
Subdomains are independent of www canonicalization. You handle www.blog.example.com separately if needed, but most sites use subdomains without www prefixes. The redirect logic applies only to the primary domain’s www variant, not to functional subdomains.