XenForo Tutorials

[TUTORIAL] How to force HTTPS on your forum using .htaccess

Submitted by tivum, , Thread ID: 51861

Thread Closed
18-10-2017, 02:22 PM
This post was last modified: 18-10-2017, 02:30 PM by tivum
#1
As we all know, Google admitted that having an SSL certificate will make your website ranking a little bit better, it also secures the website. Today i'm going to show you how to force https on your website.

First you need to open up your document root whether that's a folder called www/ or maybe public_html/
You need to find your .htaccess file. NOTE: If you're on cPanel file manager, you're dotfiles will be hidden, dotfiles are files like .htaccess and files that begin with a dot, you'll need to go up in the right hand corner and click the settings button and click show dotfiles (hidden).

You then want to go to your document root and file your .htaccess file and open it to edit it.

Important:If you have existing code in your .htacess, add this above where there are already rules with a similar starting prefix.


Code:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]


Be sure to replacewww.example.comwith your actual domain name.
To force aspecific domainto use HTTPS, use the following lines of code in the .htaccess file in your website's root folder:

Code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]


Make sure to replaceexample\.comwith the domain name you're trying force to https. Additionally, you need to replacewww.example.comwith your actual domain name.
If you want to force SSL on a specific folder you can insert the code below into a .htaccess file placed in that specific folder:

Code:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://www.example.com/folder/$1 [R,L][/size][/color]

Make sure you change thefolderreference to the actual folder name. Then be sure to replacewww.example.com/folderwith your actual domain name and folder you want to force the SSL on.

I hope i've helped someone, if you have any questions feel free to ask and i'll try to help to the best of my ability.

Users browsing this thread: 2 Guest(s)