【发布时间】:2019-07-11 00:45:13
【问题描述】:
我的网站有证书,但它不是通配符证书。所以它是针对 example.com,而不是针对 *.example.com。
我认为没问题,我会通过 mod_rewrite 将任何访问者重定向到正确的 URL:
RewriteEngine On
RewriteBase /
# Following two lines to strip machine name
RewriteCond %{HTTP_HOST} !^example.com [NC]
RewriteRule ^(.*)$ https://example.com%{REQUEST_URI} [L,R=301]
# Following two lines make sure the https version is always served
RewriteCond %{HTTPS} off
RewriteRule (.*) https://example.com%{REQUEST_URI} [L,R=301]
现在,重定向确实有效。当有人输入https://www.example.com/page时,他最终会被重定向到https://example.com/page。
但是……
浏览器首先显示https://www.example.com 不安全的警告。只有当我添加异常时,它才会被重定向到https://example.com/page,它不会给出证书错误...
我在这里做错了什么?
【问题讨论】:
标签: apache .htaccess mod-rewrite https