Non WWW to WWW .htaccess Redirect

This task becomes more insignificant as search engines continue to evolve and become more sophisticated. Canonical tags are the largest step toward making this an unnecessary task, but as an SEO best practice it’s worth five minutes of your time to assist the proper indexation of your site.

Why do I need the non-www to www redirect?

With all the unique files and paths to these files on the Web it’s easy for a crawler to see the below as two separate files:

https://trevorayers.com
https://www.trevorayers.com

You want all authority your you build through your efforts to be accredited to one URL. Now you just have to choose a version. Google uses the www subdomain, so that’s good enough for me.

Should I Redirect to the www or Non-www Version of my Domain?

Creating a brand new website, this is an arbitrary decision. Though, I tend to lean toward the www. If your website has a legacy then you can either plug both the www and non www into Open Site Explorer and use the variant that has the most authority. If neither version stands above the other then so a Google search for “site:yourdomain.com” without quotes and use the variant Google has picked up for its index:

www redirect

How do I do the non-www to www redirect?

Unless you’re using a Windows server this will be done through your .htaccess file. Simply paste the below script and make sure you swap your URL information in:

#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^trevorayers.com [NC]
RewriteRule ^(.*)$ https://www.trevorayers.com/$1 [L,R=301,NC]

Your .htaccess file will be found on your server in the same folder as your index file. Make sure your FTP program can view hidden files and add the above.

If you would like to do the opposite of this and redirect the www to the non-www then add the below script to your .htaccess file:
#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.trevorayers\.com [NC]
RewriteRule ^(.*)$ https://trevorayers.com/$1 [L,R=301]

You may also like...

Leave a Reply

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