How to Force SSL with htaccess

How to Force SSL with htaccess

Table of contents

No heading

No headings in the article.

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 👍😊