We can redirect the non-SSL query of your website to an SSL port by using the .htaccess file in the website’s public folder. If the file is not there, you can create it.
1- Create/Open the file .htaccess
2- Add the following redirect rule.
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
If your site is in a sub-folder, use this code:
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} folder RewriteRule ^(.*)$ https://yourdomain.com/folder/$1 [R,L]
Don’t forget to replace yourdomain.com with your actual domain name.
How to add HTTP to the HTTPS redirection rule from cPanel?
You can also define the redirect rule from the cPanel of the website. Please follow the steps given below:
1- Log in to cPanel.
2- Click to “Redirects” under the “Domains” tab.
3- Define the rule from here.
That’s it.