Apache how to set HTTP to automatically jump to HTTPS

Source: Internet
Author: User

Https://www.cnblogs.com/niejunlei/p/5279677.html

How do I set HTTP to automatically jump to HTTPS?

Apache environment, after configuring HTTPS, you need to set the URL redirection rules, so that the Site page HTTP access to automatically go to HTTPS access.

1, first open URL redirection support 1) Open apache/conf/httpd.conf, find #LoadModule rewrite_module modules/mod_rewrite.so Remove the # number. 2) Find the <Directory> section of your site directory, such as my Site Directory is c:/www, find
<directory "C:/www" >
...
</Directory>
Modify the allowoverride None to allowoverride all 3) Restart Apache Service 2, set redirection rules   1) A. htaccess file is placed on your site directory. In a Windows environment, you cannot rename a file directly to. htaccess, and you will be prompted to enter a file name. So let's start with a new "new text document. txt" document, open Notepad, select Save As, type select "All Files (*. *)", file name ". htaccess", save. This generates a. htaccess file.

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]

Explain:
%{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, it means localhost.

The above rule means that if the port of the URL being accessed is not 443 and the access page is not tz.php, then the rule is applied rewriterule. This is achieved: access to the http://localhost/index.php or http://localhost/admin/index.php and other pages will automatically jump to https://localhost/index.php or https://localhost/admin/index.php, but when you visit http://localhost/tz.php, you don't make any jumps, which means http://localhost/tz.php and https:/ /localhost/tz.php two addresses can be accessed.

Apache how to set HTTP to automatically jump to HTTPS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.