CloudLinux.ro
Networking & DNS

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 pricing

Related tutorials