我在安装wordpress的时候遇见了这个报错请问是什么原因该如何解决Mixed Content The page at URL was loaded over HTTPS but requested an insecure stylesheet URL This request has been blocked; the content must be served over HTTPS
这个错误提示是因为你的网站使用了 HTTPS,但是请求的样式表(stylesheet)是不安全的 HTTP 协议。这会导致浏览器拦截请求,因为 HTTPS 与 HTTP 不兼容,为了保证安全性,必须使用安全的 HTTPS 协议。
解决方法:
- 使用 HTTPS 的样式表
找到请求的样式表,将其链接地址改为 HTTPS 的链接地址。如果你的网站使用的是 WordPress,可以在主题的 functions.php 文件中添加以下代码来强制使用 HTTPS 加载样式表:
function enqueue_scripts_and_styles() { wp_enqueue_style( 'style', get_stylesheet_uri(), array(), null ); } add_action( 'wp_enqueue_scripts', 'enqueue_scripts_and_styles' );
- 使用 CDN
使用 CDN(内容分发网络)可以使你的样式表等静态文件使用 HTTPS 加载,同时提高网站的加载速度和安全性。常用的 CDN 服务有 Cloudflare、MaxCDN等。
- 在 .htaccess 文件中添加规则
在 .htaccess 文件中添加以下规则可以强制使用 HTTPS 加载样式表:
Redirect to HTTPS
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Force SSL for stylesheets and scripts
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*.(css|js))$ https://%{HTTP_HOST}/$1 [L,R=301]
以上是三种解决方法,你可以根据自己的需要选择一种合适的方式来解决问题
原文地址: http://www.cveoy.top/t/topic/hjIJ 著作权归作者所有。请勿转载和采集!