How to Redirect Non-WWW to WWW URLs (2026 Guide)

How to Redirect Non-WWW to WWW URLs

If your website is accessible at both example.com and www.example.com, search engines treat them as two separate URLs — even though they load the same content. Without a proper redirect, this duplication can split ranking signals, confuse crawlers, and create inconsistent user experiences. Setting up a non-www to www redirect solves this by sending all traffic to a single, canonical version of your domain.

This guide walks through why the redirect matters and exactly how to implement it correctly.

Why You Need a Non-WWW to WWW Redirect

Why You Need a Non-WWW to WWW Redirect

When both example.com and www.example.com load successfully without redirecting to one another, search engines may index both versions separately. This creates duplicate content issues, dilutes backlink equity between two URLs instead of consolidating it into one, and can lead to inconsistent tracking data in analytics tools.

A redirect fixes this by picking one version — in this case, the www version — as the canonical domain, and automatically forwarding all non-www requests to it.

Choosing WWW as Your Canonical Domain

Whether you redirect to www or non-www is largely a preference, but once you choose, consistency is what matters most. If your existing backlinks, branding, or historical traffic favor the www version, redirecting non-www traffic to it preserves that equity rather than starting over. The key is to pick one version and apply the redirect uniformly across your entire site.

Using a 301 Redirect (Not a 302)

Using a 301 Redirect (Not a 302)

Always use a 301 (permanent) redirect, not a 302 (temporary) redirect, when pointing non-www URLs to www. A 301 tells search engines the move is permanent, so they transfer ranking signals — including link equity — to the destination URL. A 302 signals a temporary change and won’t consolidate those signals the same way, which defeats the purpose of the redirect.

How to Set Up the Redirect

The exact method depends on your server environment. Below are the most common approaches.

Apache (.htaccess)

For Apache-based hosting, add the following to your .htaccess file in the root directory:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^example\.com [NC]

RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

Replace example.com with your actual domain. This rule checks whether the request is coming from the non-www host and, if so, forwards it to the www version with a 301 status code. The $1 preserves the full page path, so a visit to example.com/about correctly lands on www.example.com/about rather than the homepage.

Nginx

If your site runs on Nginx, add a server block that catches the non-www domain and redirects it:

server {

    listen 80;

    server_name example.com;

    return 301 https://www.example.com$request_uri;

}

This should sit alongside your main server block that serves www.example.com. The $request_uri variable preserves the full page path, so example.com/about redirects to www.example.com/about instead of dropping visitors on the homepage.

Hosting Control Panel

Many hosting providers, including cPanel-based setups, offer a redirect or domain management tool where you can select the non-www version and point it to www without editing server files directly. This is often the simplest route if you’re not comfortable editing .htaccess or Nginx configuration.

Cloudflare Page Rules or Redirect Rules

If your domain uses Cloudflare, you can create a redirect rule that matches example.com/* and forwards it to https://www.example.com/$1 with a 301 status. This works at the DNS/CDN level, so it applies before the request even reaches your hosting server.

Verifying the Redirect Works Correctly

After implementing the redirect, confirm it’s functioning as intended:

  • Visit http://example.com and https://example.com in a browser and confirm both land on https://www.example.com.
  • Use a redirect-checking tool to confirm the response returns a 301 status code, not a 302 or a chain of multiple redirects.
  • Check that internal links, sitemaps, and canonical tags across your site consistently reference the www version to avoid working against the redirect.
  • After changing your preferred URL structure, verify that Google Search Console and your XML sitemap consistently reference the www version, so indexing tools reflect the same canonical domain as your redirect.

Common Mistakes to Avoid

  • Redirect chains: Avoid situations where non-www redirects to HTTP www, which then redirects again to HTTPS www. If your site also redirects HTTP to HTTPS, combine both redirects into a single rule whenever possible — sending non-www HTTP requests straight to https://www.example.com — instead of chaining separate hops.
  • Missing SSL coverage: If your SSL certificate doesn’t cover both www and non-www versions, visitors may hit a certificate warning before the redirect can even execute. Confirm your certificate covers both.
  • Inconsistent canonical tags: If your redirect points to www but your canonical tags or sitemap still reference non-www, you’re sending mixed signals to search engines.
  • Using 302 instead of 301: As noted above, this prevents proper consolidation of SEO signals.

Final Thoughts

Redirecting non-www to www is a small technical change with a meaningful SEO impact. It consolidates your site into a single canonical URL, preserves link equity, and removes duplicate content risks. The setup takes only a few minutes through your server configuration, hosting panel, or CDN — but skipping it can quietly cost you rankings and consistency over time.

Table of Contents