Skip to content

How to Redirect www to non-www

Key idea:

A single canonical domain is SEO rule #1. Pick one (usually non-www) and 301-redirect the other. Setup: nginx — separate server block for www with return 301; Apache — RewriteRule in .htaccess; Cloudflare — Page Rule. You need a cert for both (usually wildcard or SAN).

Below: step-by-step, working examples, common pitfalls, FAQ.

Step-by-Step Setup

  1. Decide: www or non-www as canonical. Most pick non-www (shorter, more modern)
  2. Ensure DNS has A records for both: example.com and www.example.com
  3. SSL cert must cover both. Let's Encrypt: certbot -d example.com -d www.example.com
  4. In nginx create a separate server block for www with return 301
  5. In Apache — RewriteRule in .htaccess or vhost
  6. Verify: curl -I https://www.example.comHTTP/1.1 301 Moved Permanently, Location: https://example.com
  7. Check with Enterno Redirects Checker — should be HTTP→HTTPS→non-www chain, no loops
  8. Update canonical, sitemap.xml, robots.txt on the target domain

Working Examples

ScenarioConfig / Record
nginx minimalserver { listen 443 ssl; server_name www.example.com; ssl_certificate /path/fullchain.pem; return 301 https://example.com$request_uri; }
Apache .htaccessRewriteEngine On RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Cloudflare Page RuleURL: www.example.com/* → Forwarding URL → 301 → https://example.com/$1
Reverse: non-www → wwwserver_name example.com; return 301 https://www.example.com$request_uri;
curl testcurl -ILk https://www.example.com 2>&1 | grep -iE "HTTP|Location"

Common Pitfalls

  • 302 instead of 301 — search engines do not transfer link equity
  • Double hop HTTP→HTTPS→www→non-www — 1-5% ranking loss from the chain
  • SSL cert only on one variant — the other returns ERR_CERT_COMMON_NAME_INVALID
  • DNS missing record for www — Server not found on attempt
  • Redirect loop (A→B→A) from a wrong RewriteCond condition
Redirect ChainsEach extra redirect adds 100-300ms latency and reduces PageRank along the chain.
HTTP to HTTPSVerify the redirect is performed correctly without intermediate unencrypted hops.
Redirect LoopsCircular redirects cause ERR_TOO_MANY_REDIRECTS error and complete page unavailability.
301 vs 302 Codes301 permanently passes PageRank, 302 is a temporary redirect without passing SEO weight.

Why teams trust us

10+
redirect hops
HTTPS
redirect check
<2s
result
301/302
redirect codes

How it works

1

Enter URL

2

Redirect chain followed

3

Codes & final URL shown

Redirect checker: optimize redirect chains

Incorrect or long redirect chains slow down the site, lose PageRank and confuse search crawlers. The tool visualizes the full redirect chain with response codes and timing for each hop.

Full hop chain

Shows each redirect step: URL → code → URL → code, through to the final destination.

Time per hop

Measures latency at each redirect step for precise identification of performance bottlenecks.

Redirect type

Distinguishes 301, 302, 303, 307, 308 — each has different behavior for SEO and browsers.

Loop detection

Automatically detects circular redirects and warns before the browser throws an error.

Who uses this

SEO

redirect chain audit

Developers

301/302 debugging

DevOps

HTTPS redirect check

Marketers

UTM link tracking

Common Mistakes

Chains of 3+ redirectsHTTP → HTTPS → non-www → www — that's three redirects instead of one. Merge them into a single direct redirect.
Using 302 instead of 301302 for permanently moved pages means losing PageRank. Use 301 for final migrations.
Redirecting HTTP to HTTP before HTTPSAn intermediate unencrypted hop creates an MITM vulnerability and adds an extra request.
Not updating internal linksRedirects are not a substitute for updated links. Links to original URLs should be updated directly.

Best Practices

Use one redirect: HTTP+www → HTTPS+non-wwwConfigure a single nginx/Apache rule combining both conditions into one 301 redirect.
Check redirects after migrationsDomain change, HTTPS migration, URL structure redesign — all create new redirect chains.
Remove stale redirectsRedirects accumulated over years create hidden chains. Audit .htaccess and configs quarterly.
Control redirects in sitemapSitemap should only contain final URLs without redirects — otherwise crawlers waste crawl budget.

Get more with a free account

Redirect check history and API for automated chain auditing.

Sign up free

Learn more

Frequently Asked Questions

www or non-www — which is better for SEO?

Doesn't matter — pick ONE canonical and use it consistently. Google and Yandex have long treated both equally.

Do I need a cert on www if the redirect is instant?

Yes. The client first establishes TLS with www.example.com — the cert must be valid. Only then does the server return 301.

Difference between 301 and 308?

301 — permanent, allows method change POST→GET. 308 — same but preserves method. For www→non-www use 301 — universally supported.

How do I test for redirect loops?

<a href="/en/redirects">Enterno Redirects Checker</a> shows the chain and warns on loops. Or <code>curl -I -L</code> (follows redirects) — more than 10 hops = problem.