混合内容页:请求一个不安全的样式表错误


Mixed Content Page: requested an insecure stylesheet error

我有一个网站在工作。当我用http://协议打开任何页面时,所有东西都正确加载,但是当我尝试用HTTPS协议加载页面时,页面加载但没有CSS和javascript文件。
控制台显示以下错误。

混合内容:页面在"https://www.example.com/index.php?main_page=login"已加载通过HTTPS,但请求一个不安全的样式表"http://www.example.com/site_map.html"。这个请求已经被阻塞;内容必须通过HTTPS提供。

我认为问题是浏览器不能加载任何css文件时,它通过https协议请求。
问题是与htaccess文件,因为当我删除它,css文件正确加载。

页面和css文件加载到浏览器中使用https在他们的url像这样

<link rel="stylesheet" type="text/css" href="https://www.example.com/includes/templates/classic/css/style1.css">
<link rel="stylesheet" type="text/css" href="https://www.example.com/includes/templates/classic/css/style2.css">
当浏览器尝试加载CSS文件时,它被重定向到
http://www.example.com/site_map.html  

如何使htaccess允许https打开特定文件夹中的css和js文件?

谢谢

http文件内容

RewriteEngine On
RewriteCond %{SERVER_PORT} ^443$
RewriteRule (.*) http://www.example.com/$1 
###############################################################################
# Common directives
###############################################################################
# NOTE: Replace /shop/ with the relative web path of your catalog in the "Rewrite Base" line below:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example'.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}' /index'.php' HTTP/
RewriteRule ^index'.php$ http://www.example.com/ [R=301,L]
#RewriteBase /
###############################################################################
# Start Ultimate SEO URLs
###############################################################################
# Original (unchanged) URL formats
RewriteRule ^(.*)-p-([0-9]+)(.*)$ index'.php?main_page=product_info&products_id=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-c-(.*)-p(.*)'.html$ /index.php?main_page=$4&cPath=$2&sort=$5&page=$3
RewriteRule ^(.*)-c-([0-9_]+)(.*)$ index'.php?main_page=index&cPath=$2&%{QUERY_STRING} [L]
RewriteRule ^(.*)-ez-(.*).html$ index.php?main_page=page&id=$2 [L]
# All other pages
# Don't rewrite real files or directories
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index'.php?main_page=$1&%{QUERY_STRING} [L]

# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*'([^)]*') [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|'[|'%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|'[|'%[0-9A-Z]{0,2})
RewriteRule   index.html$  index.php [QSA] 

# 480 weeks
<FilesMatch "'.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=290304000, public"
</FilesMatch>
# 2 DAYS
<FilesMatch "'.(xml|txt)$">
Header set Cache-Control "max-age=172800, public, must-revalidate"
</FilesMatch>
# 2 HOURS
<FilesMatch "'.(html|htm)$">
Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
RewriteEngine on
RewriteBase /
ErrorDocument 404 /index.php
RewriteRule   index.html$  index.php [QSA]

如果你能够通过HTTPS服务CSS等,最好的解决方案是使用//作为资产url的方案。

这意味着"使用与父文档相同的方案(有时称为协议)",即如果页面使用https,则使用https。例如:
<link rel="stylesheet" href="//mysite.com/styles.css">
<script src="//mysite.com/app.js"></script>

你的问题是:

RewriteCond %{SERVER_PORT} ^443$
RewriteRule (.*) http://www.example.com/$1 

您不允许SSL请求(443端口号用于HTTPS请求)。

很可能在你的html代码中有像

这样的东西
<link href="http://someSite.com/css/someStyle.css" rel="stylesheet" type="text/css" />

应该改成

<link href="https://someSite.com/css/someStyle.css" rel="stylesheet" type="text/css" />

你所指的页面是。html不是css,但我猜这是一个错别字。

在Drupal 8.0.1中遇到类似的错误

错误 - 混合内容:页面"是通过HTTPS加载的,但请求了一个不安全的样式表"。此请求已被阻止;内容必须通过HTTPS提供

解决方案 -打开.htaccess文件,添加以下行报头总是设置Content-Security-Policy "upgrade-不安全的请求;"

您可能还需要检查您的WordPress地址(URL)站点地址(URL)在常规设置下,确保你的URL是https://www.yourdomain.com

我使用了cloudflare的插件,在他们的指南中有描述。