How to force redirect URL from HTTP to HTTPS?

Sometimes we dont know that only SSL certificate installation is not sufficient for your website security. If someone hit url with http then server will allow them to browse without enabling https. As a result SSL will not properly utilized.

We can easily do this with the help of .htaccess file. In this tutorial i will explain how to redirect all your http request into https.

What is .htaccess?

An .htaccess file is used for an Apache web server as a way to configure the details of your website without altering the server configuration files. This file begins with a period to signify that it’s hidden within the folder. An .htaccess file can be used to load customized error pages (such as 404 pages), create URL redirects, implement password-protected authentication for specific directories on your server, and many more.

Steps to force redirect:

  1. Create a .htaccess file on your root directory of the project
  2. Copy and paste the code given below
  3. Save the file and check

This code will only worked for that directory which contains .htaccess file. & remember this is compatible for apache linux server. 

Share:

Leave your Comment

© 2025 Tanvir's Blog | All Rights Reserved