Apache Mandatory www jump and forced HTTPS encryption jump method

Source: Internet
Author: User
Tags free ssl free ssl certificate ssl certificate

Generally I will be more use of the WordPress program, its installation when we open directly with WWW, or in the background set WWW domain name will be forced by default 301 point to the WWW site domain name. And there are other blog programs that use Zblog or Typecho will not default to 301 jump. Theoretically from the user experience, or from the search engine, preferably a unified or WWW, or not with the WWW format of the URL.

So, I am going to use 301 in Apache to force the WWW format, where I am using Apache virtual Host environment so directly in the root directory of the. htaccess file settings.

First, mandatory www jump

Rewriteengine on
Rewritecond%{http_host} ^cnbanwagong\.com [NC]
Rewriterule ^ (. *) $ http://www.cnbanwagong.com/$1 [L,R=301,NC]

Added to the pseudo-static file, takes effect immediately.

Second, mandatory HTTPS format

Because the HTTPS encryption format URL is also in a succession of popular and must, so I also consider and adjust to add HTTPS format URLs, after all, free SSL certificate is also more, add is not complex, just after testing is still possible, but also need to be HTTPS mandatory jump, Because HTTP and HTTPS are also best-only.

Rewriteengine on
Rewritecond%{server_port} 80
Rewriterule ^ (. *) $ https://www.cnbanwagong.com/$1 [r,l]

Similarly, you can add a forced https jump to a. htaccess file.

Third, add 301 jump

Rewriteengine on
Rewritecond%{http_host}!^cnbanwagong.com$ [NC]
Rewriterule ^ (. *) $ https://cnbanwagong.com/$1 [l,r=301]
Rewritecond%{server_port} 80
Rewriterule ^ (. *) $ https://cnbanwagong.com/$1 [l,r=301]

If we have friends like to use the format without WWW, so we can also force without WWW jump and HTTPS mandatory without www.

Apache Mandatory www jump and forced HTTPS encryption jump method

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.