Forcing SSL with .htaccess, cPanel & CloudFlare

HostBastic

Well-known member
Hosting Provider
Registered
Joined
Nov 17, 2016
Messages
320
Points
28
Using the following code in your .htaccess file automatically redirects visitors to the HTTPS version of your site:

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

If you have an existing .htaccess file:

- Do not duplicate RewriteEngine On.
- Make sure the lines beginning RewriteCond and RewriteRule immediately follow the already-existing RewriteEngine On.


Forcing SSL via cPanel follow this steps:

- access the redirects section
- set permanent (301) redirect
- choose the domain name
- enter the site's url using the SSL certificate
- make sure wild card redirect is selected
- select redirect with or without www


Forcing SSL via CloudFlare follow this steps:

- Login into your CloudFlare account, choose the domain which you wish to enforce the SSL.
- From there select the Page Rules section and select Create Page Rules.
- Add your URL and select Add a Setting.
- Under Add a Setting select SSL and for SSL Settings choose Full.
 

Maxoq

Well-known member
Registered
Joined
Feb 25, 2015
Messages
520
Points
28
This is a good option to force SSL (https) with .htaccess file
By the way, you know ways to enable SSL for websites that using Cloudflare or enable SSL from cPanel ?
 

HostBastic

Well-known member
Hosting Provider
Registered
Joined
Nov 17, 2016
Messages
320
Points
28
If you wish to force SSL via cPanel follow this steps:

- access the redirects section
- set permanent (301) redirect
- choose the domain name
- enter the site's url using the SSL certificate
- make sure wild card redirect is selected
- select redirect with or without www

With CloudFlare you can do so by creating a page rule which enforces HTTPS for the selected URL.
 

Maxoq

Well-known member
Registered
Joined
Feb 25, 2015
Messages
520
Points
28
If you wish to force SSL via cPanel follow this steps:

- access the redirects section
- set permanent (301) redirect
- choose the domain name
- enter the site's url using the SSL certificate
- make sure wild card redirect is selected
- select redirect with or without www
Thanks for the tips!
I could do this on my cPanel.

With CloudFlare you can do so by creating a page rule which enforces HTTPS for the selected URL.
Can you go into the details for this step with some screenshots or where I can create and how to setup them?
 

HostBastic

Well-known member
Hosting Provider
Registered
Joined
Nov 17, 2016
Messages
320
Points
28
HostBastic
1. Login into your CloudFlare account, choose the domain which you wish to enforce the SSL.
2. From there select the Page Rules section and select Create Page Rules.
3. Add your URL and select Add a Setting.
4. Under Add a Setting select SSL and for SSL Settings choose Full.
 

hostens

Well-known member
Hosting Provider
Registered
Joined
Jan 18, 2017
Messages
215
Points
28
If you want to enforce SSL only on specific page of your website you can change .htaccess rule as follows:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule register.php https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]​

Where "register.php" would be part of website that needs to be encrypted.
 

24x7serverman

Well-known member
Hosting Provider
Registered
Joined
Jul 25, 2017
Messages
651
Points
28
Thanks for sharing the article. :)

I would like to provide one more tip - SSL used to work from the server where your website is pointing so you should always install the SSL from the server where your site is hosted and working.


For green padlock in browser, you will need to replace every instance of http to https and will need to update your site and home URL in database.
 
Latest Threads
Replies
1
Views
24
Replies
0
Views
179
Replies
1
Views
39
Replies
2
Views
81

Latest postsNew threads

Latest Hosting OffersNew Reviews

Sponsors

Tag Cloud

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top