How to redirect non www to www for WordPress

how to redirect www to non www on WordPress

There are no rules about which version ( “WWW” or “non-WWW”) of your domain name you should use. It's all a matter of personal preference.

But choose you must! But, since a lot of you are just here for the code, we'll get to the point. If you're interested in learning more about how this works and why it's important, you can skip past the code for now.

Redirecting WWW to non-WWW

First, update WordPress settings
Any time your site's domain changes, make sure to update “WordPress Address” and “Site Address” under “Settings” > “General”.

Next, find and open your .htaccess file
You'll need to use some sort of file manager or FTP client to access and edit .htaccess. If you aren't comfortable doing this, contact your hosting support.

Lines to add to .htaccess
RewriteEngine on

# redirects www to non www - also redirects any other domain pointed here to
RewriteCond %{HTTP_HOST} !^yourdomain\.com$
RewriteRule ^(.*)$$1 [L,R=301]

Redirecting non-WWW to WWW

RewriteEngine on

# redirects non www to www - also redirects any other domain pointed here to
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$
RewriteRule ^(.*)$$1 [L,R=301]

How it Works

Go to in a new window. Note that it automatically changes back to This is the result of a 301 (permanent) redirect in my .htaccess file.

Why a Redirect is Important

Making sure that only one version of your domain can be used to access your pages is necessary for SEO (Search Engine Optimization). Neglecting to do this can cause duplicate content issues.

Without this redirect in place, the same page will be accessible via both and These 2 urls might look pretty much the same, but to a computer (search engine crawler), they are two completely separate addresses.

This problem, better know as duplicate content, makes it harder for search engines to crawl and index a website. And creating barriers between search engines and your content breaks my golden rule of SEO. “Only provide your best content to search engines, and make it as easy as possible for them to access it.”

Thanks for reading, and free to reach out if you have any questions.

Share This: