在问题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指出,如果您只有一个经过认证的域,则应遵循该顺序。
就我而言,我只有https://www.example.com
的SSL证书,而没有https://example.com
的SSL证书。我正在使用以上.htaccess
设置,因此我没有颠倒顺序。
当我输入http://example.com
时,我希望它首先被重定向到https://example.com
(由于L
标志)并发出类似的警告
令我惊讶的是,它已正确重定向到https://www.example.com
。
为什么这不重定向到https://example.com
并引发警告?