【发布时间】:2016-04-29 20:32:33
【问题描述】:
在 httpd.conf 中,我在 httpd.conf 中编写了从不安全重定向到安全的规则(例如,http://example.com -> https://www.example.com),
但是当站点已经是 https 时,您如何在 www 前面加上前缀?
例如,如果我在浏览器中输入https://example.com,我找不到让apache 将其重写为https://www.example.com 的方法。相反,我收到证书错误,因为我的证书仅适用于“www.example.com”域。
我目前的试验是:
AllowOverride All
RewriteEngine On
# If www is not present:
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC,OR]
# ... or if https is not present:
RewriteCond %{HTTPS} off
# ensure www and https both present
RewriteRule .? https://www.example.com%{REQUEST_URI} [NC,L]
当我输入“https://example.com”时,上述内容不会在前面加上“www”(希望得到https://www.example.com的结果)
我认为正在发生的事情:我对 https://example.com 的初始请求在执行重定向之前引发了证书不匹配错误。
附带问题:我无法让 google 接受自签名的 *.example.com 证书。如果通配符证书有效,则上述内容不会成为问题。
【问题讨论】:
标签: apache .htaccess httpd.conf