Apache environment. htaccess pseudo static forced HTTPS jump access settings

Source: Internet
Author: User
Tags ssl certificate
Yesterday was busy to relocate several of the company's overseas space sites to the Asian nodes of the virtual host, because there are several sites in the form of HTTPS Web site SSL certificate, because forgot to force HTTPS jump, I also forgot to set this, Because the relocation directly after the use of HTTPS access is not a problem, so it has passed, today by colleagues found that directly after the site has not forced to jump past.
Because the virtual host is using the Apache server architecture, we can directly add to the. htaccess pseudo static file in the root directory, and the specific operation is simple.
A-root directory
The code is as follows Copy Code
Rewriteengine on
Rewritecond%{server_port} 80
Rewriterule ^ (. *) $ https://laobuluo.com/$1 [r,l]
If our site is in the root directory, add the file directly above to the. htaccess file in the current root directory, notice that the red text is replaced with our own URL.
B-Sub Directory
The code is as follows Copy Code
Rewriteengine on
Rewritecond%{server_port} 80
Rewritecond%{request_uri} subfolder
Rewriterule ^ (. *) $ https://laobuluo.com/subfolder [r,l]
This is in the corresponding subdirectory (subfolder), we replace our URLs according to the actual needs, and the corresponding subdirectories.

Summary, on such a simple setup, you can force HTTP to jump HTTPS URLs

Above from: http://www.itbulu.com/htaccess-https.html

First, with the WWW jump to without the WWW domain name

The code is as follows Copy Code

Rewriteengine on
Rewritecond%{http_host}!^111cn.net$ [NC]
Rewriterule ^ (. *) $ http://111cn.net/$1 [l,r=301]

Second, jump to www domain without www

The code is as follows Copy Code

Rewriteengine on
Rewritecond%{http_host} ^111cn.net [NC]
Rewriterule ^ (. *) $ http://www.111cn.net/$1 [l,r=301]

Generally is to use the above 2 methods, remember that it does not matter, with the old left the same record down, the next time to use the direct copy used.
New add if the site moved, old domain name all 301 jump to the new site:

  code is as follows copy code

Rewriteengine On
Rewriterule ^ (. *) $ http://www.111cn.net/$1 [r=301,l]

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.