How to Redirect Non-WWW to WWW And Why It Matters To SEO

Ray Wang

Before digging into how to redirect non-www. to www. or vice versa of a domain, we want to briefly discuss the structure of a domain.

A domain name structure is broken into three sections:

  • Top-level domain: Top-level domain, also known as TLD, refers to the .ca, .com, etc. of the domain structure. For example, .ca is the TLD of www.rwdigital.ca.
  • Domain name: The domain name is the root domain of the domain structure. rwdigital is the domain name of www.rwdigital.ca.
  • Subdomain: Subdomain is the prefix before the domain name. For example, www. is the subdomain of www.rwdigital.ca

Htaccess Redirect

It’s important to redirect www. to non-www. or vice versa so there’s one central domain structure of your website. If you have the instances of two URLs and neither one redirects to one location, then you’d encounter duplicate content issues. Google would see two unique websites with the exact same content and the search engine would think that you’ve created multiple websites using the same content and try to rank multiple ranks on search results. Google would then penalize you by de-indexing your websites or dropping your ranking. Neither outcome is desirable.

To prevent encountering such issues, you can redirect www. to non-www or vice versa by writing the following codes in your .htaccess file.

Redirect to non-www.

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Redirect to www.

RewriteEngine on
RewriteCoud %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.example.com%{REQUEST_URI} [L,R=301]

Please remember to change https://www.example.com to your website URL.

If you have any questions about setting up www. to non-www. or vice versa or SEO, please feel free to get in touch via form below.

ABOUT RW DIGITAL

RW Digital is a strategic and technical digital consulting agency that provides actionable insights through digital analytics and develop and execute digital marketing roadmaps to help brands continue to grow their companies.

Copyright ©2019 RW Digital. All rights reserved.