CityHost.UA
Help and support

How to configure HTTPS on an OpenCart site

 5764
17.04.2020
article

Before setting up https for OpenCart, you need to buy and install a suitable SSL certificate in advance. You can do it yourself (following ready-made instructions) or with the help of your hosting provider's technical support.

And be sure to back up your website and database. In case of force majeure, you can easily restore the performance of the site. This condition is not mandatory, but strongly recommended.

After the preparatory manipulations, you can start configuring https for OpenCart.

Editing configuration files

To begin, go to your hosting and find the config.php file. It is located in the root directory of the website. Then edit the URL by changing http to https. The result will be like this:

// HTTP

define ('HTTP_SERVER', 'https://site.ua/');

// HTTPS

define ('HTTPS_SERVER', 'https://site.ua/');

Then open the admin folder, find the config.php file and add the https protocol :

// HTTP

define ('HTTP_SERVER', 'https://site.ua/admin/');

define ('HTTP_CATALOG', 'https://site.ua/');

// HTTPS

define ('HTTPS_SERVER', 'https://site.ua/admin/');

define ('HTTPS_CATALOG', 'https://site.ua/');

How to configure HTTPS in OpenCart admin panel?

At this stage, setting up https for OpenCart is done as follows:

  1. Go to the administrative panel. It opens at http://sait.ua/admin. migration of OpenCart to HTTPS
  2. Open the "System" section and go to "Settings". Click on the edit icon opposite the site. opencart https setting
  3. Open the "Server" tab. In the item "Use SSL", check "Yes" and save the changes.

How to configure HTTPS redirection in .htaccess?

To transfer the site on OpenCart to HTTPS, you need to configure the automatic redirection of users who come to the old address from HTTP. For this, the appropriate rules are written in the .htaccess file (located in the root directory of the web resource). You need to insert them between the lines RewriteEngine On and RewriteBase /.

For web resources with a main mirror without www, the following rules are prescribed :

RewriteCond% {HTTP_HOST} ^ www \. (. *) $ [NC]

RewriteRule ^ https://%1%{REQUEST_URI} [R = 301, L]

RewriteCond% {HTTP: X-Forwarded-Proto} = http [OR]

RewriteCond% {HTTP: X-Forwarded-Proto} = ""

RewriteCond% {HTTP: X-HTTPS}! 1 [OR]

RewriteCond% {HTTPS}! = On

RewriteCond% {REQUEST_URI}! Robots \ .txt

RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R = 301, L]

And if the domain com.ua of the site with www :

RewriteCond% {HTTP_HOST}! ^ Www \. (. *) $ [NC]

RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R = 301, L]

RewriteCond% {HTTP: X-Forwarded-Proto} = http [OR]

RewriteCond% {HTTP: X-Forwarded-Proto} = ""

RewriteCond% {HTTP: X-HTTPS}! 1 [OR]

RewriteCond% {HTTPS}! = On

RewriteCond% {REQUEST_URI}! Robots \ .txt

RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R = 301, L]

Then check that everything works. That is, when you try to visit the site with www or without www at the old address (c http), you are automatically redirected to the appropriate mirror with https. If everything is normal, the transition work is considered successfully completed.

Now you know how to configure https for OpenCart . As you can see, there is nothing complicated - it is enough to edit the configuration files, making small changes.


Like the article? Tell your friends about it: