htaccess无法理解^ www \.规则,如果将参数附加到url [英] htaccess does not understand ^www\. rule , if paramters are appended to url
问题描述
.htaccess无法理解^www\.
规则
.htaccess does not understand ^www\.
rule
#do not use this, because i want to redirect from https://www.somedomain.com
#RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTP_HOST} ^somedomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.somedomain\.com$
RewriteRule ^/?$ "https\:\/\/somedomain\.com" [L,R=301]
#[NE,L,R=301] - NE|noescape
这会进行以下重定向,尽管速度很慢:
This gives the following redirections, though very slow:
somedomain.com-> https://somedomain.com
somedomain.com --> https://somedomain.com
www.somedomain.com-> https://www.somedomain.com
www.somedomain.com --> https://www.somedomain.com
somedomain.com/folder/file-> https://somedomain.com/folder/file
somedomain.com/folder/file --> https://somedomain.com/folder/file
www.somedomain.com/folder/file-> http://www.somedomain.com/folder/file
www.somedomain.com/folder/file --> http://www.somedomain.com/folder/file
最后一个URL www.somedomain.com/folder/file未重定向到https.为什么?
the last url www.somedomain.com/folder/file is not redirected to https. WHY?
推荐答案
[OR]
还有其他条件,可能导致过多的重定向.通过使用以下命令对其进行修复:
You have an additional condition with [OR]
that can cause too many redirects. Fix it by using:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.somedomain\.com$ [NC]
RewriteRule ^/?$ https://somedomain.com [L,R=301]
在测试之前完全清除浏览器缓存.
Completely clear browser cache before testing this.
这篇关于htaccess无法理解^ www \.规则,如果将参数附加到url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!