How to Force HTTPS Redirect Using .htaccess

Domain · 1 min read

Guide to adding a redirect rule in your .htaccess file so all visitors are automatically directed to the HTTPS version of your website.

Digitalku hosting activates SSL automatically. However, visitors can still access your website via unencrypted http://. To ensure all visitors are always redirected to https://, add the following redirect rule to your .htaccess file.

Redirect Code

Add the following to your website's .htaccess file:

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

How to Edit the .htaccess File

  1. Log in to cPanel
  2. Open File Manager and navigate to the public_html folder
  3. Find the .htaccess file, right-click it, and select Edit
  4. Add the code above and save the file

Can't see the file? The .htaccess file is hidden by default. In cPanel's File Manager, click Settings in the top-right corner and check Show Hidden Files.

Chat Support

We're here to help

Available Mon–Sun, 08:00–22:00 WIB