Setting HTTPS and www in .htaccess

Find the .htaccess file in the folder where your index.html file is.

This will force anyone who visits your site to go to the HTTPS version of the site (Secure) and with the "www" subdomain. 

By default, many websites show duplicate content without a subdomain i.e. benbrenner.com and with the www subdomain (www.benbrenner.com)

In the last few years Google has begun penalizing sites that allow this because as they are crawling your site, they see duplicate pages.  For you to rank high in google, they want your information to be unique from the rest of the internet. 
# Canonical https/www
<IfModule mod_rewrite.c>
	RewriteCond %{HTTPS} off [OR]
	RewriteCond %{HTTP_HOST} !^www\. [NC]
	RewriteCond %{HTTP_HOST} ^(.*)$  [NC]
	RewriteRule (.*) https://www.%1/$1 [R=301,L]
</IfModule>

This tip comes from https://htaccessbook.com/htaccess-redirect-https-www/

0 thoughts on “Setting HTTPS and www in .htaccess

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>