In SEO, canonicalizing your URLs is very important. One of the first steps in this process is making sure all of your pages include (or exclude) www in your domain. This quick post will show you how to easily do this.
Add this to the beginning of your .htaccess file (it might already be there):
Once RewriteEngine on is added, add two of the following blocks of code directly below it. If you have any 301 redirects, place them after whichever block you choose. None of the text below is a placeholder — in other words, don't change anything about the text. Any text that follows after the number sign (#) is a comment, and can be removed.
Block 1 — protocols
For the first block, we need to specify whether we want our domain to be accessed via http or https.
Block 2 — www
We've got everything redirecting to a single protocol, now we'll specify whether we want our domain to use www.