简体   繁体   English

将所有流量重定向到https:// www。 目前,我有两个版本http:// www和https:// www

[英]Redirect all of the traffic to https://www. Currently I have two versions http://www and https://www

I have a brand new site, initially, it was http:// then I redirected the site to http://www it worked liked a charm, but since I installed the SSL I have two versions of website http://www.example.com and https://www.example.com . 我有一个全新的网站,最初是http://,然后将其重定向到http:// www ,但它确实很吸引人,但是由于安装了SSL,所以我有两个版本的http:// www。 example.comhttps://www.example.com I have tried several commands in .htaccess but still I have two versions can someone please help me with this, below is the code I am using in my .htaccess: 我在.htaccess中尝试了几个命令,但仍然有两个版本,有人可以帮助我吗,以下是我在.htaccess中使用的代码:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

First www and after https: 第一个www和https之后:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

Try this one. 试试这个。

RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM