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

Javascript 混合内容页:请求的样式表错误不安全,javascript,php,css,.htaccess,https,Javascript,Php,Css,.htaccess,Https,我有一个网站在做这件事。当我使用http://protocol打开任何页面时,所有内容都已正确加载,但当我尝试使用https协议加载页面时,页面已加载,但没有css和javascript文件控制台显示以下错误 混合内容:页面位于 “”已加载 通过HTTPS,但请求了不安全的样式表 ''. 这项请求已被批准 此 路 不通;内容必须通过HTTPS提供 我想问题是浏览器在https协议请求时无法加载任何css文件 问题在于htaccess文件,因为当我删除它时,css文件加载正确 页面和css文件加载

我有一个网站在做这件事。当我使用http://protocol打开任何页面时,所有内容都已正确加载,但当我尝试使用https协议加载页面时,页面已加载,但没有css和javascript文件
控制台显示以下错误

混合内容:页面位于 “”已加载 通过HTTPS,但请求了不安全的样式表 ''. 这项请求已被批准 此 路 不通;内容必须通过HTTPS提供

我想问题是浏览器在https协议请求时无法加载任何css文件
问题在于htaccess文件,因为当我删除它时,css文件加载正确

页面和css文件加载到浏览器,URL中包含https,如下所示

<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">
如何使htaccess允许https打开特定文件夹中的css和js文件

谢谢

更新 htaccess文件内容

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]
重新编写引擎打开
重写cond%{SERVER_PORT}^443$
重写规则(.*)http://www.example.com/$1 
###############################################################################
#共同指令
###############################################################################
#注意:在下面的“重写基线”行中,用目录的相对web路径替换/shop/:
选项+FollowSymLinks
重新启动发动机
RewriteCond%{HTTP_HOST}^example\.com$[NC]
重写规则^(.*)$http://www.example.com/$1[R=301,L]
重写cond%{THE_REQUEST}^[A-Z]{3,9}\/index\.php\HTTP/
重写规则^index\.php$http://www.example.com/ [R=301,L]
#重写基/
###############################################################################
#开始终极搜索引擎优化网址
###############################################################################
#原始(未更改)URL格式
重写规则^(.*)p-([0-9]+)(.*)$index\.php?主页=产品信息和产品id=$2&%{QUERY\u STRING}[L]
重写规则^(.*)-c-(.*)-p(.*)\.html$/index.php?主页=$4&cPath=$2&sort=$5&page=$3
重写规则^(.*)-c-([0-9_]+)(.*)$index\.php?主页=index&cPath=$2&%{QUERY\u STRING}[L]
重写规则^(.*)-ez-(.*).html$index.php?主页=page&id=$2[L]
#所有其他页面
#不要重写真实的文件或目录
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index\.php?主页=$1&%{QUERY\u STRING}[L]
#阻止任何试图在URL中对数据进行base64_编码的脚本。
RewriteCond%{QUERY\u STRING}base64\u encode[^(]*\([^)]*\)[或]
#阻止在URL中包含标记的任何脚本。
重写cond%{QUERY_STRING}(|%3E)[NC,或]
#阻止任何试图通过URL设置PHP全局变量的脚本。
重写条件%{QUERY\u STRING}全局(|\[|\%[0-9A-Z]{0,2})[或]
#阻止任何试图通过URL修改_请求变量的脚本。
重写条件%{QUERY\u STRING}\u请求(|\[|\%[0-9A-Z]{0,2})
RewriteRule index.html$index.php[QSA]
#480周
标题集缓存控制“最大年龄=290304000,公共”
#2天
标题集缓存控制“最大年龄=172800,公共,必须重新验证”
#2小时
标题集缓存控制“最大年龄=7200,必须重新验证”
#压缩文本、html、javascript、css、xml:
AddOutputFilterByType泄气文本/普通
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE应用程序/xml
AddOutputFilterByType DEFLATE应用程序/xhtml+xml
AddOutputFilterByType DEFLATE应用程序/rss+xml
AddOutputFilterByType DEFLATE应用程序/javascript
AddOutputFilterByType DEFLATE应用程序/x-javascript
重新启动发动机
重写基/
ErrorDocument 404/index.php
RewriteRule index.html$index.php[QSA]

在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,但我想这是一个输入错误…

如果您能够通过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请求)。请尝试删除这些行。

我使用了cloudflare的插件,如指南中所述。

在Drupal 8.0.1中遇到类似错误

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

解决方案-打开.htaccess文件并添加以下行
标题始终设置内容安全策略“升级不安全的请求;”

您可能还需要检查
WordPress地址(URL)站点地址(URL)在“常规设置”下,确保页面加载https和css文件时url为

,url也使用https。因为当浏览器操作它时,服务器对重定向页面的响应为“”,在我的情况下,我的css文件中有一个http。更改为htpps也有效。谢谢!@loannis Loukeris,'http'和'hhtps'应该是动态的。用户可以使用任何一种浏览器进行浏览。感谢这正是问题所在。它还可以加快页面加载速度。因此,这有助于我一举两得。最佳实践表明,您不应该将域放入代码中。您错过了URL的域“即,如果页面使用https,则使用https”有一秒钟我很困惑,但是你的例子确实起了作用:用///替换了所有的http://导致文件找不到。你能发布
.htaccess
的内容吗?我更新了问题,你帮助解决这个问题的问题来自AWS beanstalk环境中托管的laravel应用程序。我刚刚将文本添加到我的public/.htaccess文件中。Thanks
RewriteCond %{SERVER_PORT} ^443$
RewriteRule (.*) http://www.example.com/$1