嗨,我正在按照标题尝试通过.htaccess将整个网站重定向到HTTPS。
这是我的代码:
# Rewrite all to HTTPS apart from Lets Encrypt requests
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# End HTTPS Rewrite
由于某种原因,此代码本身不允许来自let加密的请求,但可以通过在上面添加用户代理的条件和规则来起作用:
# Rewrite all to HTTPS apart from Lets Encrypt requests
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} "^$" [NC]
RewriteRule ^.* - [F,L]
RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
# End HTTPS Rewrite
这真的让我感到困惑,为什么它可以在额外的条件下工作,而不是没有,有人知道吗?
谢谢