Automatically Redirect HTTP Website Traffic to HTTPS via .htaccess File

https website security

You will, of course, need an SSL website security certificate, but once you have one, you’ll want to configure your server so that your visitors and clients are automatically. You can see how this works by typing https://joshrobertnay.com (http not https) in the address bar of your browser and this site will redirect you to the secure https URL. Not only does this serve to make your website more secure, but it also helps improve your site’s SEO.

Finding .htaccess file in cPanel

This redirect is relatively simple to implement if you’re familiar with the layout of cPanel. You’ll need to navigate to your File Manager. Once you’re there, you can click on the Settings button at the top right of the page as indicated in green below below.

cPanel File Manager in cPanel Internet Hosting

From there, click the Show Hidden Files box as shown below.

Show Hidden Files in cPanel

Now go back to the root of your File Manager and search for .htaccess or simply browse the files to see if the file exists. If not, at this point you can create one by clicking +File and entering .htaccess under New File Name. Then Create New File. If it’s there, highlight the file, and select Edit. Confirm Encoding if prompted.

READ: Boost Your Website by Enabling Compression via Your Server .htaccess File in cPanel or Through FTP

The .htaccess file could be blank if you’ve created one or might otherwise have some code already on it. In any case, simply enter the following code into the file:

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

Be sure to make sure the RewriteEngine On rule doesn’t already exist. If it does, don’t duplicate it. You’ll also want to make sure RewriteCond and RewriteRule commands immediately follow RewriteEngine On. Now Save Changes when done.

Alternatively, you can perform these steps through FTP in clients like FileZilla.

Your website will now redirect from the http version to https.

For Advanced users only. Please utilize the code only if you know what you’re doing or have your web administrator do it for you. This site is not responsible for any liability caused by incorrect usage of this code or your web server.