htaccess的重定向非www到www,而preserving HTTP和放大器; HTTPS [英] htaccess for redirecting non-www to www while preserving http & https

查看:251
本文介绍了htaccess的重定向非www到www,而preserving HTTP和放大器; HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站刚刚得到的EV SSL证书。在过去,我已经重定向非www请求,WWW使用htaccess的 - 和它的工作好

My site just got its EV SSL certificate. In the past I've redirected non-www requests to www using htaccess - and it worked well.

但现在,如果我要求一个HTTPS页面,我结束了(通过htaccess的重定向)的HTTP版本。

But now, if I request a https page, I end up (via the htaccess redirect) on the http version.

我需要htaccess的重定向是这样的:非www重定向到www,而preserving HTTP或HTTPS

I need htaccess to redirect like this: non-www redirects to www, while preserving the http or https

下面是我用现在的htaccess文件:

Here is the htaccess file I'm using now:

Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

这是不工作的权利。该HTTPS请求将被重定向到HTTP。

It isn't working right. The https requests are being redirected to http.

推荐答案

试试这个:

Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301,QSA]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301,QSA]

这篇关于htaccess的重定向非www到www,而preserving HTTP和放大器; HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆