One of the Most requested questions asked by our customers about how they can redirect their website to open in HTTPS instead of HTTP. Well, that’s the easiest, or we can say copy and paste job!
Here are Complete Guides for How to Set HTTPS for the website in .htaccess file as well how to create .htaccess file and some useful rules to add in .htaccess. This guide will set to work with all hosting platforms as well as created around cPanel like Control Panel.
Prerequisite:
- Website should point on web hosting server
- Valid SSL Certificate already installed
- Save all files to local PC before opening it and changing codes inside just for safety
If you want to install SSL Certificate for your website using cPanel then follow this guide: How to Install Let’s Encrypt SSL in cPanel
Scene 1: Load Website in HTTPS through .htaccess file
Step 1:
In order to create .htaccess file you need to login to your cPanel. After successfully log into it Search for ‘File Manager’ in your cPanel.
Step 2:
Inside File Manager on Top-right cornor there’s ‘Settings’, Open that menu and Tick ✅ Show Hidden Files option and press ‘Go’ button.
Step 3:
Now head to root directory of your website. Search for file named .htaccess in root directory.
If there is not .htaccess file then create one and Google about default .htaccess file and paste code whichever you like on internet.
– Noobie googler
Step 4:
Open that file, just after syntax like
RewriteEngine On RewriteBase /
Paste below-mentioned code for HTTP to HTTPS
RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] Header always set Content-Security-Policy "upgrade-insecure-requests;"
Now save file the file. Clear browser cache and type and open http:// version of your website’s URL. You’ll see site will automatically loads with https:// and will show Green SSL Certificate PadLock.
Scene 2: Add www to website with https
This Scene is not suggest for all kind of users, it can throw some error and need some prior knowledge of htaccess ruleset.
As always save files to your local PC before changing anything to play safe if something goes wrong!
Step 1:
Follow above mentioned steps from 1 to 3 of Scene 1 as it is described.
Step 2:
As mentioned in Step 4 in above Scene 1, just right after syntax like shown below
RewriteEngine OnRewriteBase /
Add following code from below:
#For www and https enabled RewriteCond %{HTTP_HOST} !^www\. RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] #Now, rewrite to HTTPS: RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
And now your site will load with https://www. Instead of some nonsense you don’t want!
Share Your Comments & Feedback