If you have an SSL certificate installed on your domain and you would like to ensure all visitors are directed to the secure version of your website (HTTPS), you can achieve this by adding specific rules to your .htaccess file. This guide will show you how to force HTTPS using the .htaccess file in cPanel.
Step-by-Step Guide:
Forcing HTTPS for Your Entire Website
-
Log in to your cPanel account:
- Open your web browser and navigate to your cPanel login page.
- Enter your username and password to access the cPanel dashboard.
-
Navigate to the File Manager:
- In the cPanel dashboard, scroll down to the "Files" section.
- Click on the "File Manager" icon.
-
Locate your .htaccess file:
- In the File Manager, navigate to the root directory of your website (usually
public_html
). - If you do not see a .htaccess file, click on "Settings" in the top-right corner and check the box to show hidden files (dotfiles).
- In the File Manager, navigate to the root directory of your website (usually
-
Edit the .htaccess file:
-
Right-click on the .htaccess file and select "Edit."
-
Add the following code to the .htaccess file to force HTTPS for your entire website. Replace
example.com
with your actual domain name:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
-
-
Save the changes:
- Click "Save Changes" and then close the editor.
Forcing HTTPS for a Specific Domain
-
Edit the .htaccess file:
-
Follow the same steps as above to locate and edit your .htaccess file.
-
Add the following code to force HTTPS for a specific domain. Replace
example.com
with your actual domain name:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
-
-
Save the changes:
- Click "Save Changes" and then close the editor.
Forcing HTTPS for a Specific Folder
-
Edit the .htaccess file:
-
Follow the same steps as above to locate and edit your .htaccess file.
-
Add the following code to force HTTPS for a specific folder. Replace
example.com
with your actual domain name andfolder
with the folder name you want to secure:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://www.example.com/folder/$1 [R,L]
-
-
Save the changes:
- Click "Save Changes" and then close the editor.
Additional Information:
- Removing WWW: If you do not wish for the
www.
to be included, removewww.
from the .htaccess rules. - SSL Certificate: Ensure you have an SSL certificate installed on your domain before applying these rules.
Troubleshooting:
- No .htaccess File: If you cannot find the .htaccess file, you can create a new one in the root directory of your website.
- Errors or Issues: If you encounter any errors or issues after making changes, you can revert the changes by removing the added code from the .htaccess file.
If you have any issues forcing HTTPS using .htaccess, please don't hesitate to contact our support department for assistance.
For further assistance, contact our support team or refer to this cPanel Blog on the subject.
Looking for reliable Linux hosting with Award Winning Customer Support?
Grab your hosting today with a 20% discount. All plans come with our 60 Money Back Guarantee!
Check out our plans & promotions on our website -- https://www.peopleshost.com/