How can I force the use of SSL (HTTPS) via the .htaccess file?

 
To ensure your visitors always browse securely, you can automate the HTTPS redirection by editing the .htaccess file in your cPanel. Follow these steps: 

 

1. Inside your cPanel, go to the public_html folder.

 

public.png

 

2. Locate the .htaccess file: If it is not visible, click on Settings (top right corner) and check the box "Show Hidden Files (dotfiles)".

 

3. Right-click the file, select Edit, and paste the following snippet at the very beginning, above any existing rules:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

 

 

4. Once applied, the server will automatically redirect any insecure connection attempts.

 
Security Note:

Before making this adjustment, verify that you have an active SSL certificate (such as Let's Encrypt). If the certificate is not correctly installed, your website will show a privacy error to users.

We recommend making a backup copy of the .htaccess file before performing any modifications.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to create a Cron Job?

  A cron job is simply an automated task that runs on a server at specific time intervals. You...

How to create and configure your .htaccess file?

  The .htaccess file is a powerful tool for managing your site's security and redirection....

How can I assign different PHP versions to my domains?

  If you manage multiple projects on a single account and need each domain or subdomain to run...

How can I change PHP values (limits, execution time, errors) using "MultiPHP INI Editor" (Basic Mode)?

  Here we will explain how to transcribe and adjust these values using the "MultiPHP INI Editor"...

How can I password protect my folders in cPanel?

  Ensuring the security of your information is simple. Follow this step-by-step guide to...