Several ways Apache http automatically jumps to HTTPS

Source: Internet
Author: User
When your site uses HTTPS, you may want to redirect all HTTP requests (that is, port 80 requests) to HTTPS. You can do this in the following ways:

After the HTTPS is enabled, but also to ensure that the previous HTTP port can be opened, HTTP 80 port is two URLs, so this will lead to the original with wwww and without the WWW domain name at the same time specify an HTTPS URL above, you need to

To do two Apache 301 redirects, this is actually very simple, summer blog practice is directly in the. htaccess file to add two 301, as follows:

Rewritecond%{http_host} ^www.php.cn [NC]  rewriterule ^ (. *)? $ https://www.php.cn/$1 [r=301,l]  Rewritecond%{ Server_port}!^443$  rewriterule ^ (. *)? $ https://www.php.cn/$1 [r=301,l]


The first 301 is naturally with the WWW jump to the new https above, and the following 301 redirect is to determine if the port is not 80, then redirect, so that, with the WWW and without the WWW domain will jump to https a URL above, Of course, this whole station to do 301 of the method is more violent, usually we just have to make a primary domain name 301 on it, I am here because the original two domain name.

Topic.alibabacloud.com also mobile phone some other Apache http jump to HTTPS method, for reference only:

Method 1

Rewriteengine on  rewritebase/  rewritecond%{server_port} rewriterule  ^ (. *) $ https://www.php.cn/$1 [R= 301,L]

Method Two

Rewriteengine on  rewritecond%{server_port}!^443$  rewriterule ^ (. *)? $ https://%{server_name}/$1 [R=301,L]

#整站跳转

Method Three

Rewriteengine on  rewritebase/yourfolder  rewritecond%{server_port}!^443$  #RewriteRule ^ (. *)? $ https:// %{server_name}/$1 [r=301,l]  rewriterule ^.*$ Https://%{server_name}%{request_uri} [r=301,l]

#以上至针对某个目录跳转, Yourfolder is the directory name.

Method 4

REDIRECT 301  /Your Web page https://your host + Web page

#至针对某个网页跳转

Method 5

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 refers to 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 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 access http://localhost/tz.php will not do any jump, that is, http://localhost/tz.php and https:/ /localhost/tz.php two addresses can be accessed

  • Related Article

    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.