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.

Check your site →

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

TL;DR: Redirecting www to non-www

To redirect www to non-www, use a 301 redirect in your web server configuration or .htaccess file. For Apache, add RewriteEngine On and RewriteCond %{HTTP_HOST} ^www\.(.*)$ followed by RewriteRule ^(.*)$ http://%1/$1 [R=301,L]. For Nginx, include server { listen 80; server_name www.example.com; return 301 http://example.com$request_uri; } in your server block.

Understanding the Importance of Redirecting www to non-www

A redirect from www to non-www is crucial for maintaining a consistent domain presence and ensuring optimal SEO performance. Search engines treat www and non-www as separate entities, which can lead to duplicate content issues and diluted link equity. By implementing a 301 redirect, you inform search engines that the non-www version should be the authoritative version of your site. This practice not only consolidates traffic but also enhances your site's credibility.

Moreover, user experience plays a significant role here. Users may type either version of your domain into their browsers. By redirecting one version to another, you ensure that visitors always land on the correct site, thus reducing bounce rates and improving engagement metrics.

To implement this effectively, you need to understand the server environment your website is hosted on. Here, I will outline the steps for both Apache and Nginx, the two most commonly used web servers.

1. Redirecting www to non-www on Apache

For Apache servers, you typically use the .htaccess file to configure redirects. This file is located in the root directory of your website. If you do not have an .htaccess file, you can create one. Ensure that your server has the mod_rewrite module enabled, as this is necessary for the redirect to work.

Here’s how to set it up:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

In this configuration:

  • RewriteEngine On enables the runtime rewriting engine.
  • RewriteCond %{HTTP_HOST} ^www\.(.*)$ checks if the HTTP host starts with www.
  • RewriteRule ^(.*)$ http://%1/$1 [R=301,L] redirects the request to the non-www version while preserving the requested URI.

2. Redirecting www to non-www on Nginx

If you are using Nginx, the process is slightly different. Nginx configurations are typically found in the /etc/nginx/sites-available/ directory. You will need to edit the configuration file for your domain.

Here is a basic example of how to set up the redirect:

server {
    listen 80;
    server_name www.example.com;
    return 301 http://example.com$request_uri;
}

In this setup:

  • listen 80; specifies that the server is listening on port 80 for HTTP traffic.
  • server_name www.example.com; defines the server block for the www version.
  • return 301 http://example.com$request_uri; issues a permanent redirect to the non-www version while preserving the requested URI.

3. Testing Your Redirect

After configuring the redirect, it is essential to test it to ensure it works correctly. You can use tools like HTTP Status Checker or simply enter the www version of your domain in a web browser to see if it redirects to the non-www version.

Additionally, you can use command-line tools such as curl to verify the redirect:

curl -I http://www.example.com

This command will return the HTTP headers, and you should see a 301 Moved Permanently status along with the new location pointing to the non-www version.

4. Updating Internal Links

After implementing the redirect, ensure that all internal links on your site point to the non-www version. This consistency aids search engines in indexing your site correctly and helps users navigate without confusion.

In summary, redirecting from www to non-www is a crucial step in managing your website's SEO and user experience. By following the guidelines above, you can seamlessly implement this redirect and maintain a strong online presence.

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.

Try the live tool that powered this guide

Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.