Force SSL https using .htaccess


You have setup SSL certificate and want to show entire site from https even if user access site without https for example if user access http://yourdomain.com it should automatically redirect to https://yourdomain.com

If your script do not support internal SSL redirect then this can be easily setupĀ using this rewrite code in site .htaccess file


RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://yourdomain.com/$1 [R,L]

Replace yourdomain.com with your actual domain, Also make sure above code is added at start of .htaccess before any other rewrite code already there.

If your site do not have .htaccess simply create new text file in site root and rename it to .htaccess using File Manager or FTP client.

If you are going to serve entire site from https make sure all content including 3rd party css, js and image files are served from https otherwise your site will show SSL warning to visitors. If your site is not showing padlock SSL lock in browser and claiming there is insecure content simply check page source by using ctrl + u command in browser.

Now search for all content which do not start from https by doing search for http:// using ctrl + f

Leave a comment

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