Deprecated: Array and string offset access syntax with curly braces is deprecated in /home/myhostn/public_html/forum/Sources/Subs.php on line 4412

Deprecated: Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in /home/myhostn/public_html/forum/Sources/Load.php on line 3372
Print Page - Force HTTPS Connections

HostNed Community

FAQs and KNOWLEDGEBASE => SSL and HTTPS => Topic started by: Dynaweb on May 08, 2022, 10:18:38 am

Title: Force HTTPS Connections
Post by: Dynaweb on May 08, 2022, 10:18:38 am
Forcing HTTPS on All Website Traffic

HTTPS is the new standard in secure online connections for web pages. It ensures that connections are not being intercepted and instills confidence for your visitors.

When you enable HTTPS on your web site using an installed SSL certificate, you may still be able to load your pages using the traditional non-HTTPS connections, so to get things as secure as possible, it is recommended to enable https:// connections all the time. It is a good idea to enable this unless there is something that will not work in https mode for some reason. cPanel calls this "Force HTTPS redirect. You can find that setting under DOMAINS in your cPanel area. This is available for your main domain name only, so to force HTTPS connections on your subdomains and/or add-on domains, you can do that by adding some code to your .htaccess file.

Here is how to use the .htaccess file to force HTTPS redirects:

Go to File Manager in cPanel (or Plesk) and find .htaccess inside the public_html folder. Be sure to make a backup copy first just in case something goes wrong. If you can't find it, make sure to unhide hidden files in the settings.
Scroll down to find RewriteEngine On and insert the following lines of code below it:

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

Save the changes.
Important! Make sure that the line RewriteEngine On is not repeated twice. In case the line already exists, simply copy the rest of the code without it.

Force HTTPS on a Specific Domain Only
Let's say that you have two domains: and Both domains access the same website, but you only want the first one to be redirected to the HTTPS version. In this case, you need to use the following code:

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

Make sure to replace yourdomain1 with the actual domain you're trying to force HTTPS on.

Forcing HTTPS on a Specific Folder
The .htaccess file can also be used to force HTTPS on specific folders only. However, the .htaccess file should be placed inside the folder that will have the HTTPS connection.

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(folder1|folder2|folder3) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

After making the changes, clear your browser's cache and try to connect to your site via HTTP. If everything was added correctly, the browser will automatically redirect you to the HTTPS version.

Even though your connections are now being automatically redirected to HTTPS. you may want to update your links in your website code to the new updated https:// address for best practice.