Redirect rightly your Opencart site after SSL Certificate installation : Force SSL Trick

If you have already installed SSL certificate with your domain and still your domain is not redirecting or showing “https” then here is very simple solution which you need to follow.
first create .htaccess file in your domain root (hosting) and make below changes:

1. Changes in your .htaccess file for redirect your “naked domain” to “www” and redirect “http://” to “https://” :

Code: Select all

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS} on
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

2. Changes in your “config.php” index file

Code: Select all
<?php
// HTTP
define('HTTP_SERVER', 'https://www.marginprice.com/');
define('HTTP_IMAGE', 'https://www.marginprice.com/image/');
define('HTTP_ADMIN', 'https://www.marginprice.com/admin/');

// HTTPS
define('HTTP_SERVER', 'https://www.marginprice.com/');
define('HTTP_IMAGE', 'https://www.marginprice.com/image/');
define('HTTP_ADMIN', 'https://www.marginprice.com/admin/');

 

3. Changes in your /admin/config.php file

Code: Select all

<?php
// HTTP
define('HTTP_SERVER', 'https://www.marginprice.com/admin/');
define('HTTP_CATALOG', 'https://www.marginprice.com/');
define('HTTP_IMAGE', 'https://www.marginprice.com/image/');

// HTTPS
define('HTTP_SERVER', 'https://www.marginprice.com/admin/');
define('HTTP_CATALOG', 'https://www.marginprice.com/');
define('HTTP_IMAGE', 'https://www.marginprice.com/image/');

please change Marginprice.com to your domain name.

How to force HTTPS using the .htaccess file?
To force all web traffic to use HTTPS insert the following lines of code in the .htaccess file in your website’s root folder.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Be sure to replace www.example.com with your actual domain name.

To force a specific domain to use HTTPS, use the following lines of code in the .htaccess file in your website’s root folder:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

Make sure to replace example\.com with the domain name you’re trying force to https. Additionally, you need to replace www.example.com with your actual domain name.

If you want to force SSL on a specific folder you can insert the code below into a .htaccess file placed in that specific folder:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://www.example.com/folder/$1 [R,L]

Make sure you change the folder reference to the actual folder name. Then be sure to replace www.example.com/folder with your actual domain name and folder you want to force the SSL on.

Are you getting “error undefined” in OpenCart 2.1 after installing SSL when you viewing your order info?

First of all find this line in /admin/controller/sale/order.php
$data['store_name'] = $order_info['store_name'];

below or after above line, you will see below line
$data['store_url'] = $order_info['store_url'];
Or (depends opencart version)
$data['store_url'] = $this->request->server['HTTPS'] ? preg_replace("/^http:\/\//", "https://", $order_info['store_url']) : $order_info['store_url'];

Remove any of above line whatever you find and replace with this below line
$data['store_url'] = $this->request->server['HTTPS'] ? HTTPS_CATALOG : HTTP_CATALOG;

To see effect logout from your opencart admin page and login again. If still problem coming let us know.

We have tested this trick in “Opencart” if you are using another shopping cart or software then you have to find config.php file in your host for make changes.

[SOLVED] https lock not showing green? Don’t know why no or yellow padlock?

Please give us your feedback if your problem solved, if this trick is not working let us know if any error.

Thank you

1 Comment
  1. Good job and bunch of thanks for this valuable post.

    Leave a reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Marginbaba
    Logo
    Register New Account