在这个问题上
htaccess redirect to https://www
答案基本上是这样的:
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.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
第二
higest upvoted answer
声明如果您只有一个认证域,那么您应该尊重该顺序。
在我的情况下,我只有一个ssl证书
https://www.example.com
但不是为了
https://example.com
. 我在用上面的
.htaccess
设置,所以我没有颠倒顺序。
当我进入
http://example.com
我希望它先被重定向到
https://example.com网站
(因为
L
并发出警告
令我惊讶的是,它被正确地重定向到
https://www.example.com网站
.
为什么不重定向到
https://example.com网站
然后发出警告?