Menu
Your Cart
Tutorial 3.1 - How to Redirect HTTP to HTTPS on OpenCart

Tutorial 3.1 - How to Redirect HTTP to HTTPS on OpenCart

Tutorial 3.1 - How to Redirect HTTP to HTTPS on OpenCart

Redirects from HTTP to HTTPS on OpenCart can technically be done via the .htaccess file.

We will explain how to redirect from HTTP to HTTPS on OpenCart.

Why you should redirect from HTTP to HTTPS?

before, you must know about the difference between these domain below:
1. www.hpwebdesign.io
2. http://www.hpwebdesign.io
3. https://www.hpwebdesign.io
4. https://hpwebdesign.io
5. https://hpwebdesign.io

This will be a reference for the website system. Especially if there is image content that uses absolute links, such as {website.com address}/{image_file_address.jpg}.
 
More than that, Google will also consider it a different domain. This means, if you don't redirect the web to one address Google will index more than one version of your website. And this is not great for SEO. Because Google will detect duplicate content that lowers your content rankings.
 
Not only that, there are other technical problems if you don't redirect to HTTPS. Especially if you are currently using OpenCart, then there will be problems like:
1. Icon does not appear when opening the homepage
 
This happens very often on OpenCart websites, where the fontawesome icon does not appear when opening the front page for the first time. This is because the user is accessing a different website address than the URL defined in config.php.
 
Unfortunately, if customers see this as a mistake, they may leave your website.
 
2. Unable to add product to cart
 
Accessing the website from the wrong URL will result in the product not being added to the shopping cart. This one is quite fatal.
 

Intro Setting SSL on OpenCart

SSL (Secure Socket Layer) is a web protocol used for encryption of data communication between a web browser and a web server. So that the exchange of data between the browser and the web server takes place more securely. Because all the data is encrypted.

What are the benefits? The main thing is the security of data exchange because often e-commerce contains very important credentials. More than that, activating SSL will increase the trust of your customers.

Safe SSL Sign on Browser

Safe SSL Sign on Browser

The green color with the lock symbol on the browser will be active. More than that you are free from the insecure flags of the Chrome browser. Where it is active on websites without SSL. So you can lose customers, especially for those who are concerned with SSL.

SSL Configuration on OpenCart

Follow these steps to configure SSL on OpenCart:
1. Login to the administration page
2. Access the page: System → Settings.
3. Edit Store. Switch to the Servers Tab. See the security section.
4. Select Yes on the Use SSL option.

SSL activation on OpenCart

Redirect from HTTP to HTTPS

1. How to redirect HTTP to HTTPS

How to redirect HTTP to HTTPS in this article will be done via the .htaccess file. You can also redirect via cpanel if you wish. But, redirect via .htaccess file in our opinion is more flexible:

1. Login to Cpanel and open the file manager. Or open your FTP client for remote file transfer to hosting.

2. Access the public_html/ directory or another directory which is the main directory of your OpenCart installation.

3. Make sure the htaccess file has been renamed to: .htaccess

4. If so, then add the following line at the end of the file:

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
5. Save

2. How to redirect HTTPS to HTTP

If your web address does not use https, in the same way add the following line in .htaccess

RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

 

3. How to redirect WWW to Non-WWW

 

If your web address does not use www, in the same way add the following line to .htaccess

RewriteCond %{HTTP_HOST} ^www.your-web.com [NC]
RewriteRule ^(.*)$ http://your-web.com/$1 [L,R=301]

4. How to redirect Non-WWW to WWW

 

If your web address uses www, in the same way add the following line to .htaccess

RewriteCond %{HTTP_HOST} ^your-web.com [NC]
RewriteRule ^(.*)$ http://www.your-web.com/$1 [L,R=301]

Combine the use of http, https, www and non-www above. Because you can only have one version of the website that is accessed.

5. How to redirect WWW to Non-WWW and HTTP to HTTPS

 

For this purpose simply add the following line of code in your OpenCart .htaccess.

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R]

That's how to redirect http to https on the OpenCart web.

Hope it is useful.

Please leave a comment if you have any questions regarding the above discussion.