How to force SSL/TLS (HTTPS)

How to force SSL/TLS


Method 1: Using .htaccess file
Step 1.
Open a FTP connection to your web server (or open file browser if hosted locally)

Step 2.
Navigate to your website's root directory. Typically "www" or "public_html"

Step 3.
Open and edit your .htaccess file (which should be inside "www" or "public_html"

Step 4.
Paste the following code into the beginning of the file

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Method 2: Using PHP (Inside the file)
Step 1.
Navigate to the html tag "<head>" and enter a new line.

Step 2.
Paste the following code

<?php
if($_SERVER["HTTPS"] != "on")
{
header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
exit();
}
?>

  • SLL, TLS, HTTPS, HTTPS REDIRECT, FORCE SSL/TLS, FORCE HTTPS
  • 3 Users Found This Useful
Was this answer helpful?

Related Articles

How to create your own email

In this article we will explain how to create an e-mail account on your web server using cPanel....

How to create a database

In this article we will be creating a database using cPanel. This article assumes you have a...

How to install MyBB

Recommendations Basic understand of SQL Basic understanding of FileZilla Dependencies...