SSL securely transforms data from the client to the server by adding encryptions. Before it was used to protect transactions and customer data, but now it has become Google’s official Internet ranking factor.
Once you subscribe and install SSL on your website, the website starts using both HTTP and HTTPS URLs which means visitors landing on HTTP from old links such as old search archives or links on other websites will continue to land on HTTP. Whereas visitors using the new HTTPS will get HTTPS. Here you will need to make sure that all visitors must land on secure HTTPS URLs of your website and that can only be done by enforcing SSL all over your website.
To force your website to use HTTPS on all links you will need to redirect HTTP to HTTPS and there are various methods of doing this.
Redirecting HTTP To HTTPS Via cPanel
- Simply log in to your hosting account and open cPanel.
- In cPanel, navigate to ‘Domains’ and toggle the “Force HTTPS Redirect” option for your domain.
Redirecting HTTP To HTTPS Via .htaccess File
Another way of enforcing SSL is by adding a few lines of code in .htaccess file which is located in the root directory of your website.
- Log in to your hosting account and open cPanel.
- Navigate to cPanel -> File Manager
- Open Public_HTML and then the directory where your website is located. If your website is on the main domain i.e. yourdomain.com then it would be located in the Public_HTML directory itself.
- Add the following code and save the file.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Or, for forcing SSL over one specific domain name use this code:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.url.com/$1 [R,L]
Or, for forcing SSL over some such as domain.com/subdir. First, create a new .htaccess file in that specific directory and then add the following code:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} subdir
RewriteRule ^(.*)$ https://www.url.com/subdir/$1 [R,L]
If you see some existing code in your .htacess file then add these lines on the top where rules start with similar prefixes.
By default .htaccess is kept as a hidden file so if don’t find it on your cPanel hosting’s file manager then click the ‘Settings’ icon (visible on the top right corner of the file manager) and tick ‘Display hidden files’ option.
And if you don’t find any .htaccess file in the file manager then probably your website is not using such .htaccess file. In that case, simply create one by naming it .htaccess and then open it for editing.
Don’t forget to change domain.com with your own domain name and SUBDIR with the name of the sub directory where you want to force an HTTPS connection.
Redirecting HTTP to HTTPS In WordPress
WordPress users may simply use a plugin called Easy HTTPS Redirection (SSL). The plugin lets you automatically set up a redirection to the HTTPS version of a URL when anyone tries to access the old HTTP version.