Securing your website with HTTPS is essential for improving SEO rankings, user trust, and data security. When you install an SSL certificate, your web server may still serve HTTP pages. To ensure all traffic is redirected to HTTPS, follow this guide on how to use the .htaccess
file in cPanel.
Table of Contents
Why Redirect HTTP to HTTPS?
Redirecting HTTP to HTTPS is crucial for:
- Enhancing website security by encrypting data.
- Boosting search engine rankings (Google prioritizes HTTPS websites).
- Preventing browser warnings that may deter users.
- Ensuring compliance with security standards.
How to Redirect HTTP to HTTPS Using the .htaccess File
Follow these steps to force HTTPS on your website using .htaccess
in cPanel.
Step 1: Log in to Your cPanel
Open your web browser and navigate to your cPanel login page.
Enter your username and password, then click Log In.

Step 2: Locate or Create the .htaccess File
In cPanel, go to File Manager.
Navigate to the public_html directory.
Look for the .htaccess file. If it does not exist, create a new file named .htaccess.
Click + File at the top left.
Name the file .htaccess (include the dot at the beginning).
Click Create.

Note:- Create a new file only if there is no .htaccess file
Step 3: Add Redirect Code to .htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.Yourwebsitename.com/$1 [R,L]
Right-click on the .htaccess file and select Edit.
Copy and paste the following code into the file:
Replace yourwebsitename.com with your actual domain name.
Click Save Changes and close the file editor.
Step 4: Test the Redirect
- Open a new browser tab.
- Enter your website URL with
http://
(e.g.,http://yourwebsitename.com
). - If the redirect is successful, it should automatically switch to
https://
.
Alternative Methods for Redirecting HTTP to HTTPS
Using Nginx Server Configuration
If you’re using an Nginx server, add the following code to your configuration file:
Redirecting in WordPress
If your website runs on WordPress, you can enforce HTTPS by:
- Installing an SSL plugin like Really Simple SSL.
- Updating your WordPress Address (URL) in Settings > General.
Final Thoughts
Redirecting HTTP to HTTPS ensures a secure and SEO-friendly website. Implement the .htaccess
redirect, test your changes, and enjoy the benefits of a safer, trusted, and higher-ranking website.
Need more help? Drop your questions in the comments!