Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 对我来说,秩序似乎无关紧要https://www 重新使用_.htaccess_Ssl - Fatal编程技术网

.htaccess 对我来说,秩序似乎无关紧要https://www 重新使用

.htaccess 对我来说,秩序似乎无关紧要https://www 重新使用,.htaccess,ssl,.htaccess,Ssl,问题的答案基本上是这样的: 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=

问题的答案基本上是这样的:

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]
第二种说法是,如果你只有一个被认证的域,那么你应该重新考虑这个顺序

就我而言,我只有
https://www.example.com
但不适用于
https://example.com
。我正在使用上述
.htaccess
设置,因此我没有颠倒顺序

当我输入
http://example.com
我希望它首先被重定向到
https://example.com
(因为有
L
标志)并抛出如下警告

令我惊讶的是,它被正确地重定向到
https://www.example.com


为什么不重定向到
https://example.com
并抛出警告?

@anubhava我删除了浏览器缓存,用另一个我从未使用过的浏览器在inkognito模式下进行了尝试。它们都如上所述重定向。@anubhava好的,我检查了缓存禁用,第一个请求是
http://example.com
状态为
301
。接下来是
https://www.example.com
请求状态为
200
。没有
http://www.example.com
或a
https://example.com
请求。我怀疑有其他规则/代码从
http://example.com
https://www.example.com
在您的系统中