【问题标题】:301 Redirect in .htaccess gives certificate warning on original URL first.htaccess 中的 301 重定向首先在原始 URL 上给出证书警告
【发布时间】: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


    【解决方案1】:

    什么都没有。 SSL 协商发生在传输 (TCP) 级别,而不是 HTTP(即使使用SNI),但关键是证书对请求的域无效。当连接到www. 时,浏览器将请求证书并将url 与证书中的CN 进行比较,因为它不存在,所以它会发出警报。

    要解决此问题,您需要一个包含 ServerName 和 ServerAlias 名称的证书。您也许可以尝试一些提供 DNS HTTP 重定向的 DNS 提供商,但现在获得证书是 quite easy

    【讨论】:

      猜你喜欢
      • 2013-09-13
      • 2011-01-18
      • 1970-01-01
      • 1970-01-01
      • 2022-12-18
      • 2013-12-21
      • 2015-03-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多