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