| WordPress
How to Redirect non-WWW to WWW in WordPress

The following tutorial will show you how to redirect your WordPress site's domain from non-www to www or vice versa. Redirecting one to the other is useful for SEO.

If you go to https://www.wordpress.org, you'll see the URL changes a bit once you click enter. It goes to the non-www version. In order words, it goes to https://wordpress.org. It's a subtle change and it's usually not noticed by users.

So why have they done this? It's because, technically, the two are different domains but they have the same content. Without the redirect, they end up with duplicate content. With the redirect, they only have one site, so only one set of content.

With only one set of content, they guarantee they won't be penalized by search engines or have their ranking split.

To move your site to non-www, find your .htaccess file using your host's file manager or an FTP client.

Within it, look for the following code:

RewriteEngine On

If the code isn't there, insert it at the top of your file.

Then, to redirect non-www to www, use the following code directly below RewriteEngine On:

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

For www to non-www, use:

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

If you're on a Windows IIS server, the above code won't work for you. Please use this tutorial instead.

About the author

Nick is the Director of Support at OSTraining and you can find him in almost every area of the site, from answering support requests and account questions to creating tutorials and software.