www or non-www: how to choose and redirect correctly
Updated 7/20/2026
A site should respond on a single canonical version: either example.com or www.example.com. The other redirects to the chosen one. This avoids duplicate content and SEO problems.
1. Choose the canonical version
It does not matter much which, but be consistent. Many modern sites choose the non-www variant.
2. Configure both in DNS
example.com. A 203.0.113.10
www.example.com. CNAME example.com.
3. Redirect in Nginx
To force the non-www variant:
server {
listen 80;
server_name www.example.com;
return 301 https://example.com$request_uri;
}
nginx -t && systemctl reload nginx
4. Combine with HTTPS
Redirect to HTTPS first, then to the canonical variant, see How to force HTTPS.
SEO
Also set the preferred version in your webmaster console and use a canonical tag in the pages, so search engines index a single variant.
Put this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
Email DNS records: SPF, DKIM and DMARC
Set up SPF, DKIM and DMARC so your emails reach the inbox, not spam.
Updated 7/20/2026Networking & DNSHow to connect two servers over a private network
Link your servers through an encrypted WireGuard tunnel, so they communicate securely without exposing services to the internet.
Updated 7/20/2026Networking & DNSWhat is a CDN and when you need one
A CDN delivers content close to visitors, faster. Here is how it works and when it is worth it.
Updated 7/20/2026