我注意到在使用 HTTPS 访问网站时,当尝试从相对路径包含 CSS 或 JS 文件时,JS 控制台出现错误,例如:
<link rel="stylesheet" type="text/css" href="css/demo.css?id=14" />
Mixed Content: The page at 'https://mysiste.com/' was loaded over HTTPS, but requested an insecure stylesheet 'http://mysiste.com/css/demo.css?id=14'. This request has been blocked; the content must be served over HTTPS.
这种情况的理想解决方案是什么?
- 我是否应该强制将所有 HTTP 访问重定向到 HTTPS?
- 或者有没有办法告诉服务器使用 HTTPS 为所有相对路径提供服务?
最佳答案
相对链接将使用基本 URL 中的协议(protocol)和主机。基本 URL 通常是可以在 URL 栏中看到的那个。但是可以使用 base tag 显式更改基本 URL .
这意味着如果您在页面中设置了一个使用 http 作为协议(protocol)的基本 URL,即使您使用 https 访问该站点并且引用是相对的,它仍然会使用 http 而不是 https,即像这样:
<base href="http://example.com/">
要修复它,请删除基本标记或将其更改为使用 https 而不是 http:
<base href="https://example.com">
关于apache - 相对路径的 SSL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43983675/