How do I redirect www to non-www?

Crawvix Editorial Team · Published November 1, 2026 · Last updated November 1, 2026 · 2 min read

Add a permanent 301 redirect that sends every request for www.example.com to the same path on example.com. Keep the path and query string, switch to HTTPS in the same step, and confirm your certificate covers both names. Verify with curl that you get one 301 hop and no loop.

Why it matters

When both addresses answer, search engines and visitors can reach two copies of each page. A 301 redirect tells them the www form has moved permanently, so links, bookmarks and signals gather on the bare domain you chose.

How to do it

  1. Check that DNS for www.example.com still resolves. The redirect can only run if the old hostname reaches your server or CDN, so keep its DNS record in place.
  2. Issue or confirm an HTTPS certificate that includes both example.com and www.example.com.
  3. Add the rule. For Apache in .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
  1. For nginx, give the www name its own server block:
server {
    listen 80;
    listen 443 ssl;
    server_name www.example.com;
    # certificate lines for www.example.com go here
    return 301 https://example.com$request_uri;
}
  1. In ASP.NET Core, add middleware that checks whether Request.Host starts with www. and, if so, calls Response.Redirect with permanent: true to the same path on the bare host. If a proxy sits in front, apply the forwarded headers first so the check sees the real hostname.
  2. On a CDN or hosting panel, look for a redirect rule or a setting for the preferred host and select a permanent redirect.
  3. Test:
curl -sI https://www.example.com/blog/post?x=1

You should see 301 and location: https://example.com/blog/post?x=1. Repeat for http://www and for a deep page, not only the home page. 8. Update canonical tags, the sitemap, internal links and structured data to the bare domain, and add that property to Google Search Console if it is not there yet.

Common mistakes

  • A redirect plugin and a server rule that point in opposite directions, producing a loop.
  • Redirecting every path to the home page instead of the matching page.
  • Removing the www DNS record, which breaks old links instead of redirecting them.
  • Leaving www addresses inside the sitemap or canonical tags.
  • Using a temporary 302 redirect.

Frequently asked questions

Why do I get "too many redirects" after adding this?

Usually another setting sends visitors back to www. Check your CMS address settings, CDN page rules and any redirect plugin, and keep only one direction.

Do I need to redirect both http and https?

Yes. Each of the four combinations should reach the final address, ideally in a single hop.

Should I add the bare domain to Search Console?

Yes. A Domain property covers every variant, while a URL-prefix property covers only the exact address you enter.

Curious how your own redirects look from outside? Try the free website sample.

In this category

All 100 Quick answers guides