Skip to main content

Command Palette

Search for a command to run...

How to Force SSL with htaccess

Published
1 min read
How to Force SSL with htaccess

If you have a website running on apache2 and SSL certificate installed, but your visitors are landing on http connection sometimes, then you are in the right place.

Find your active htaccess file in the server. If there is not any, create one.

Use the below lines in the top of your htaccess file to force all users to visit your site with https

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

One important note: you need to enable ***RewriteEngine *** first.

sudo a2enmod rewrite

Thank you 👍😊

More from this blog

Sohag's Notes

79 posts

Tech Lead at MobyPay | Certified Laravel Developer | PHP JS GO | DevOps Enthusiast | Open to projects