https://www.cnblogs.com/niejunlei/p/5279677.html
How to set http to automatically jump to https?
In the apache environment, after configuring https, you need to set url redirection rules, so that http access to the website page is automatically transferred to https access.
<Directory “C:/www”>
…
</Directory>
Modify AllowOverride None to AllowOverride All
2) The editor opens the .htaccess file and writes the following rules:
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{REQUEST_URI} !^/tz.php
RewriteRule (.*) https://%{SERVER_NAME}/ $1 [R]
Explanation:
%{SERVER_PORT}——Access port
%{REQUEST_URI}——For example, if the url is http://localhost/tz.php, it means /tz.php
%{SERVER_NAME}——For example, if the url is http:/ /localhost/tz.php, refers to localhost
The above rule means that if the port of the accessed url is not 443 and the accessed page is not tz.php, the RewriteRule rule is applied. This is achieved: when visiting pages such as http://localhost/index.php or http://localhost/admin/index.php, it will automatically jump to https://localhost/index.php or https:/ /localhost/admin/index.php, but will not make any jumps when visiting http://localhost/tz.php, that is to say http://localhost/tz.php and https://localhost/tz .php is accessible from both addresses.