When a new visitor lands on a secure (https) website, he/she feels the information on web page is served securely. On the contrast, when a new visitor lands on non-secure (http) site, some of the browsers show insure page warning. Because of this, users feel less trustworthy to the site. As the world is now moving to https, the comes a need of redirection from http site.
For example, if you’ve a site that was created years ago when https wasn’t that much important. But now https is more used than http, you might be needed to redirect your older http site to https. This can be easily done by inserting a simple code in the .htaccess file for your website. The .htaccess file is usually present in the root of your website. After login to CPanel, you can go to File Manager and under public_html directory, you can spot the .htaccess file. You can highlight this file and click Edit to modify its contents.
Redirect HTTP To HTTPS Using .htaccess File
Before you redirect your site from http to https, you must have a valid SSL certificate installed on the site. Without a SSL certificate, do not try to redirect your site to https else users may got security warnings.
To redirect your website from http to https, you need to add following lines to .htaccess file (replace domain.com with your own website domain name):
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]
Note: Usually, if you’re using WordPress, the RewriteEngine On line should be already there. So you can add rest of two lines after RewriteRule . /index.php [L]
line.
In case if you’re redirecting a specific domain to utilize https, you can insert the following code to .htaccess file:
RewriteEngine On RewriteCond %{HTTP_HOST} ^domain\.com [NC] RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.domain.com/$1 [R,L]
That’s it!