How to redirect users from HTTP to https using htaccess?

You are here:
Table of Contents

After the SSL of your website has been generated, you will need to redirect your visitors from non-secured HTTP to https version. Here, we will show you how to do this using .htaccess file.

After logging in to cPanel, go to file manager > public_html You will see your website files here.

By default, the .htaccess files are hidden. You can view the hidden files on your cPanel account by clicking on Settings at the top

and Check the ” Show Hidden Files” Checkbox then click “Save“.

Now you can create a .htaccess file by clicking on this New File Icon Give the name .htaccess make sure to start the name with (.). Click “Create New File”

If you already have a htaccess file here, you do not need to create a new one. Now select the htaccess file, click on the “Edit” button from the top section. Then click on the “Edit” button again on the top button to continue, a new window will open.

On the bottom of the document, paste the following code

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

Keep in mind that the RewriteEngine ON command should not be present on the file more than one time.

RewriteCond and RewriteRule command should be directly under the RewriteEngine command as given above.

Now save the document and exit.

Your website should now redirect from the HTTP version to https automatically.

If you are still seeing an SSL issue on WordPress, installing Really Simple SSL plugin on WordPress should resolve the issue.

Was this article helpful?
How can we improve this article?

Categories

  • No categories