Force SSL from .htaccess

After converting a non-secure website to use SSL, bookmarked, and cached URLs can still be accessed from user browsers and cause your website to appear broken when the stylesheet does not load in SSL.

Force the website to always load in SSL by placing the following in your .htaccess file.

RewriteCond %{HTTPS} !on           
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]

Or like this:

# BEGIN Force HTTPS
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
    RewriteCond %{HTTPS} off [NC]
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
</IfModule>
# END Force HTTPS

Leave a Reply

katherine as a flat graphic icon

About Me

I’m an African / Ojibwe First Nations Web Developer living in Winnipeg, Manitoba.

Visit the Tips and Blog to see what I’m working on.