SSL Certificates

How To Force SSL Using .htaccess

To force all web traffic to use the HTTPS version of your URL, enter the following lines of code in the .htaccess file in your root folder.

  1. Open your website’s .htaccess file in cPanel File Manager or via FTP.
  2. Copy and paste the code below into your .htaccess file
  3. Save

.htaccess code to force https://

    # ----------------------------------------------------------------------
    # | Forcing `https://`                                                 |
    # ----------------------------------------------------------------------
    
    # Redirect from the `http://` to the `https://` version of the URL.
    # https://wiki.apache.org/httpd/RewriteHTTPToHTTPS
    
    <ifmodule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{HTTPS} !=on
      RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
    </ifmodule>

Was this guide helpful?

Need help with this?

Open a ticket and link to this guide so our team can see what you have tried.

View support tickets

Power your business with Ecenica Hosting

Built for WordPress and serious websites. Fast, secure and supported by real people in the UK.

Ecenica hosting services represented by a connected red route across London