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

时间:2016-11-19 13:08:16

标签: apache .htaccess redirect ssl mod-rewrite

我有一个全新的网站,最初是http://然后我将网站重定向到http://www它的工作很喜欢魅力,但是因为我安装了SSL,我有两个版本的网站{{3 }和http://www.example.com。 我在.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]

2 个答案:

答案 0 :(得分:1)

第一个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]

答案 1 :(得分:0)

试试这个。

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]