Redirecting requests from a non-preferred domain is important because search engines consider URLs with and without “www” as two different websites.

It creates a duplicate entry, which is not suitable for SEO.

I noticed this when you analyze your site with SEO tool, thought to share with you all.

You can redirect non-www to www or www to non-www using “.htaccess” or “httpd.conf”

www to non-www redirection

  • Ensure to take a backup of your existing file (.htaccess or httpd.conf)
  • Add the below line and save this file
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.yoursite.com 
RewriteRule (.*) https://yoursite.com/$1 [R=301,L]

Non-www to www redirection

  • Ensure to take a backup of your existing file (.htaccess or httpd.conf)
  • Add the below and save this file
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com 
RewriteRule (.*) https://www.yoursite.com/$1 [R=301,L]

Test your site again to confirm it’s working as expected.