Cpanel Tutorial

Forcing http to https access by setting redirection through .htaccess

How to setup https access

After purchasing and configuring the SSL certificate, you can still use http to access. If you want to force http to https access, you can modify Apache's .htaccess file to set it. There are three specific methods:

You only need to choose one of the following codes and put them in the .htaccess file. If there is already content in the .htaccess file, please put the redirection code at the top.

Method 1 (need to modify domain.com in the code to your own domain name):

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

Method 2 (need to modify domain.com in the code to your own domain name):

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

Method 3 (no modification required, but only applicable to the root directory of the website, use method 1 and 2 for the website of the additional domain):

RewriteEngine on RewriteBase / RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

Leave a Reply