www or non-www: how to choose and redirect correctly
Updated 10/23/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
How to find your IP address on Windows: public and local
Find your public IP address in a second and your local IP from Settings, Command Prompt or PowerShell, on Windows 10 and 11.
Updated 10/23/2026Networking & DNSHow to find your IP address on Linux: public and local
Find your public and local IP address on Linux: ip addr, hostname -I, GNOME Settings and the right way on a headless server.
Updated 10/23/2026Networking & DNSEmail DNS records: SPF, DKIM and DMARC
Set up SPF, DKIM and DMARC so your emails reach the inbox, not spam.
Updated 10/23/2026