How to redirect domain or website HTTP to HTTPS Using .htaccess file

WebSupporters Linux Hosting servers support Apache URL Rewrite module. If you have an SSL certificate on your website, you can add a few lines to your .htaccess file that will automatically redirect your visitors from HTTP to the HTTPS version of your website or domain.

To redirect domain or website HTTP to HTTPS Using .htaccess file.

  1. Be sure that the SSL Certificate is properly installed on your domain, and the website is resolving on your domain like https://example.com
  2. Login to cPanel
  3. Once logged into cPanel, click on the “File Manager” located in the Files section of cPanel.
  4. It will open a new tab in your browser and once you are in File Manager, you will see a dashboard like below.
  5. Make sure that Show Hidden Files (dotfiles) is checked, and click Save
  6. Find the .htaccess file in root directory like public_html. If your website is in a subfolder, then the .htaccess should be placed in the corresponding subfolder.
  7. Right-click on the .htaccess file and click on “Code Edit” on the menu.
  8. A dialogue box may pop up asking about encoding. Click the “Edit” button to continue.
  9. add following these rules in your website’s .htaccess file to redirect your domain or website HTTP to HTTPS:

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  10. “Save Changes” when done.
  11. Test your website to make sure it is loading without any error. In case, there is an error, restore to the previous version and try again.
  12. Once you are done, click “Close” to close the window.

 

Was this article helpful?

Related Articles