How to Force HTTPS with Opencart

Sep 8, 2020

How to Force HTTPS with Opencart

In this article we will look at how to force HTTPS with Opencart websites. The HTTPS protocol is the secure version of HTTP which is the primary protocol used to send data between a web browser and a website.

Using HTTPS is very important for SEO and also provides you with the “lock” icon on your web browser indicating your website is safe and secure for users. This is also very important for customer confidence as it they receive warning messages before entering your website it is unlikely they will be confident enough to place an order.

With that said, lets look at how to force HTTPS with Opencart.

After an SSL certificate is installed, you might see your website looking different or even broken when using the HTTPS protocol. In order to fix this you need to follow these steps:

Step 1 – Set your HTTPS URL in OpenCart config.php Files

Before you enable the SSL in your OpenCart admin dashboard, you need to edit the two configuration files of your OpenCart install. Both files are called config.php and they are located under the root directory of your OpenCart application and under the admin folder.

RIght click on each file and select “Edit”. You need to locate the following section in both of your files:

// HTTPS
define(‘HTTPS_SERVER’, ‘http://yourdomain.com/’);

You then nees to modify the URL to include the HTTPS protocol like this:

// HTTPS
define(‘HTTPS_SERVER’, ‘https://yourdomain.com/’);

Step 2 – Enable SSL via the OpenCart Admin

Now you need to activate the SSL support via the OpenCart admin dashboard.

Firstly login to your Opencart admin dashboard and proceed to the Server settings tab. And you can see Use SSL option there. Click on the Yes radio button and save your settings.

Step 3 – Force HTTPS only for your domain name

First, create a file name .htaccess in your domain folder, and put in below code, save and close, making sure you edit “yourdomain” for your own domain name.

===========

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

===========

Then, you need to open up the .htaccess file again and find this code:

=========

<FilesMatch “(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))”>

=========

You will then need to replace it with this code:

=========

<FilesMatch “(?i)((\.tpl|\.ini|\.log))”>

=========

Click save and feel free to close the file.

Once you have completed these steps you will force HTTPS with Opencart. Even if someone visits http://yourdomain.com it will automatically be redirected to the secure https://yourdomain.com.

Find more great articles in our knowledgebase.