css - 由于 CSS 背景图像,SSL 和混合内容

标签 css url ssl image https

我有一个包含报名表的网页。通过 Apache 重定向为匹配该页面的所有请求启用 HTTPS。不幸的是,由于 CSS 使用“background-image: url(/images/...)”提取外部图像,因此浏览器将生成一条警告消息,指出该页面包含混合内容。

解决此问题的最佳方法是什么?

最佳答案

Update 2014.12.17:

Now that SSL is encouraged for everyone and doesn’t have performance concerns, this technique is now an anti-pattern. If the asset you > need is available on SSL, then always use the https:// asset.

Allowing the snippet to request over HTTP opens the door for attacks like the recent Github Man-on-the-side attack. It’s always safe to request HTTPS assets even if your site is on HTTP, however the reverse is not true.

More guidance and details in Eric Mills’ guide to CDNs & HTTPS.

来源:Paul Irish – The Protocol-relative URL


这是一个非常流行的解决方案:

有一个小技巧可以让你省去一些麻烦:

在 HTML 中

<img src="//domain.com/img/logo.png">

在 CSS 中

div{background: url(//path/to/image.png);}

关于css - 由于 CSS 背景图像,SSL 和混合内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1548551/

相关文章:

Javascript 将鼠标从上到下更改为从左到右

javascript - 在浏览器中直观地更改 URL

ruby-on-rails - 将 apache SSL 反向代理与 Rails 应用程序结合使用

node.js - 使用 node.js 验证带有 CA 证书的 X509 证书

jquery - 调整大小时 Primefaces 对话框位置错误

html - CSS -> border-bottom 不显示 1.5px

php - Safari中如何处理字符为 'é'的URL?

node.js - 使用 Greenlock-Express 的通配符域的无效 SNI 错误

html - 浏览器不会反射(reflect)在 html 文件中所做的更改

javascript - 从当前 url javascript 获取字符串斜杠后的值