Force Redirect to non WWW

%%title%% %%sep%% %%sitename%%
Force Redirect to non WWW

Learn how to set up a 301 redirect to force non-WWW URLs using the .htaccess file, ensuring domain consistency and improving SEO performance.

Your site answers on two addresses: www.example.com and example.com. Pick one. If both stay live, Google sees two copies of every page, and your link equity gets split between them. Here we send www to the bare domain with a permanent redirect.

Before you touch anything

You need your root .htaccess file, and this only works on Apache with mod_rewrite enabled (Nginx does redirects a different way). Back the file up first. One stray character in .htaccess can take the whole site down with a 500, so keep a copy you can paste back.

The redirect

Open .htaccess and add this near the top:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
</IfModule>

Swap example.com for your domain in both spots. The \. escapes the dots so they match literally, [NC] makes the host match case-insensitive, and R=301 tells search engines the move is permanent so they pass ranking to the bare domain.

One honest note

Notice the redirect target is https://, not http://. Sending everyone to the secure, canonical URL in one hop is the point. If you land on http:// first and redirect again, that’s an extra round trip. So force www to non-www and http to https together, and make sure the version you keep matches what you set as your WordPress Site Address. Consistency is the whole game: one canonical host, one scheme, everywhere.

Test it

Load www.example.com in a browser. It should snap to example.com. If nothing happens, confirm mod_rewrite is on (many managed hosts enable it by default, some don’t) and check your Apache error log. Clear your browser cache too, since 301s cache hard and an old one can mask a fixed rule.

Next: Always Redirect to WWW

Leave a Comment

Your email address will not be published. Required fields are marked *


Scroll to Top