将http重定向到https,将非www重定向到www

时间:2016-11-10 12:15:44

标签: .htaccess redirect ssl

我正在使用此代码进行SSL迁移:

ConstraintLayout layout = (ConstraintLayout)findViewById(R.id.mainConstraint);
ConstraintSet set = new ConstraintSet();

ImageView view = new ImageView(this);
view.setId(View.generateViewId());
layout.addView(view,0);
set.clone(layout);
set.connect(view.getId(), ConstraintSet.TOP, layout.getId(), ConstraintSet.TOP, 60);
set.applyTo(layout);

我面临的问题是它的工作原理是重定向不适用于大多数文件夹和URL,但在少数情况下它正在工作,这就是令我困惑的事情。

如果代码是正确的,它应该适用于网站上的每个网址而不是少数网站,或者根本不应该工作。当我删除.htaccess中的第一个重写条件时,该网站工作正常。

这是我得到的错误:

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]

有人可以帮忙吗? 提前谢谢。

1 个答案:

答案 0 :(得分:1)

试试这个......

RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
相关问题