本文介绍了重定向到HTTP非www到HTTPS WWW的htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从任何方向对我们的站点使用HTTPS协议的重定向,但某些重定向它不工作。我想这样的:
I want to redirect from any direction to our site with HTTPS protocol, but some redirects it's not working. I want this:
-
http://www.site.co
到https://www.site.co
-
http://site.co
到https://www.site.co
http://www.site.co
TOhttps://www.site.co
http://site.co
TOhttps://www.site.co
这是我的htaccess的:
This is my htaccess:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]
它不工作的第二条规则。它要我们的网站在另一个方向,它不是重定向到HTTPS站点。
The second rule it's not working. It going to another direction inside our site, and it isn't redirect to HTTPS site.
推荐答案
试试这样说:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]
这里唯一的真正的区别在于,首先我们从重定向非www到WWW然后我们检查HTTPS和重定向。
The only real difference here is that first we redirect from non-WWW to WWW then we check for HTTPS and redirect it.
如果它不工作,然后试试这个:
If it does work then try this one:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]
这篇关于重定向到HTTP非www到HTTPS WWW的htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!