Redirect a WordPress site from non-WWW to WWW

How to redirect your WordPress site’s domain from non-www to www or vice versa.

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.

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

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]

 

Leave a Reply

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