How to Force Redirect HTTP to HTTPS using htaccess?

By default site reach with http://, Once an SSL certificate is installed and the site can be reached via https:// appropriately, you might want to make it accessible via https:// by default. In other words, by typing domain.com in a web-browser, a user should be redirected to https://domain.com to access the site securely.

You can force an HTTPS connection on your website by adding these rules in your website’s .htaccess file. The file itself can be found if you go to cPanel >> File Manager. There, find the document root of your website. For primary cPanel domains, the folder is usually ‘public_html’. If the website is an add-on, you can look up its document root in Addon domains section.

When you find the folder, the .htaccess file may already be there. To double-check it, click Settings in the top-right corner and tick Show hidden files (dotfiles).

If you don’t find the .htaccess there, feel free to create it by clicking +File. Make sure to name the file .htaccess, starting with the dot.

To open the file, right-click it, then click Edit. A warning box will pop up, but click on Edit.

Paste the following code and save the file.

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Header always set Content-Security-Policy "upgrade-insecure-requests;"
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to fix connection is not secure Warnings on Your Website

You are using SSL on your site and site is loading with https but showing warning “connection...

How to install Really Simple SSL Plugin ?

Login to your WP-Admin Dashboard Click on Plugins from Left Side Menu Click Add New From...

How can I install Free SSL offered by d-Webhost?

d-Webhost client who have shared web hosting and reseller hosting can install SSL from cPanel....