How to set up 301 redirect from www to non-www?
Search engines consider URLs with and without "www" as different pages so redirect from www to non-www is very important for SEO. Using a 301 redirect from www to non-www will prevent split page rankings and help avoid duplicate content in the Google index. In this tutorial, we'll show you how to set up 301 redirect from www to non-www and vice versa.
Redirect from www to non-www
Connect to your FTP server ➝ add the following source code at the beginning of your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
Redirect from non-www to www
Connect to your FTP server ➝ add the following source code at the beginning of your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]