Redirect from http to https

Using the .htaccess file

Learning

Using the .htaccess file: This file is in the root host. In order to open the site only with https or redirect all WordPress links from http to https, just enter the .htaccess file and put the provided codes depending on whether your host is Linux or Windows.

Opening the site only with https on the Linux host

To redirect all site links from http to https on the Linux host, enter the following code in your .htaccess file located in the root of the host.

Enter the below code in .htaccess file

RewriteEngine On

RewriteCond %{HTTPS} off

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

It's that easy *e.g http://hosting1.net is transferred to https://hosting1.net

By placing the above code in .htaccess, all users who visit your site, if they enter your site from search engines or links to your site on other websites or any link and in any way . Your site will be loaded with https protocol.


Important note:
If you already had the .htaccess file on your host, which naturally should be like this, you should not repeat "RewriteEngine On" again. Place the second and third lines of the above code exactly after the "RewriteEngine On" statement.
It should be noted that if you visit the single link section in WordPress even once and click on save information, the .htaccess file will be automatically created on your host.
Wordpress index: Simply add the following code above the “That’s all, stop editing!” line in your wp-config.php file: define('FORCE_SSL_ADMIN', true); This line allows WordPress to force SSL / HTTPs in WordPress admin area. It also works on WordPress multisite networks.

Opening the site only with http on the Linux host

Disabling HTTPS
To redirect all site links from https to http on the Linux host, enter the following code in your .htaccess file located in the root of the host.

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R,L]

With the above code, all requests sent to the site with the https protocol will be transferred to the http address.
For example, https://hosting1.net is transferred to http://hosting1.net.

show hidden .htaccess on cpanel