Wordpress 混合内容/不安全内容SSL

Wordpress 混合内容/不安全内容SSL,wordpress,apache,.htaccess,ssl,mixed-content,Wordpress,Apache,.htaccess,Ssl,Mixed Content,我目前有以下问题 Mixed Content: The page at 'https://www.example.com/' was loaded over HTTPS, but requested an insecure stylesheet 这是安装了httpd的Centos服务器上的Wordpress网站 我在“http.conf”中设置了以下虚拟主机: NameVirtualHost *:80 NameVirtualHost *:443 <VirtualHost *:443&

我目前有以下问题

Mixed Content: The page at 'https://www.example.com/' was loaded over HTTPS, but requested an insecure stylesheet
这是安装了
httpd
的Centos服务器上的Wordpress网站

我在“http.conf”中设置了以下虚拟主机:

NameVirtualHost *:80
NameVirtualHost *:443


<VirtualHost *:443>
    DocumentRoot /var/www/html/example
    ServerName www.example.com
    ServerAlias example.com
    SSLEngine on
    SSLCACertificateFile /etc/httpd/conf/ssl.crt/intermediate.crt
    SSLCertificateFile /etc/httpd/conf/ssl.crt/server.crt
    SSLCertificateKeyFile /etc/httpd/conf/ssl.key/server.key
</VirtualHost>

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com
    Redirect / https://www.example.com/
</VirtualHost>
我可以确认
htaccess
正在工作,因为我正在使用iTheme安全插件,并且它正在按预期工作,而且如果我在
htaccess
中键入一些垃圾,我会收到预期的服务器错误配置错误

我已将仪表板中的两个Wordpress URL都更改为使用
https
而不是
http

一旦所有这些都完成了,我就能够通过HTTP访问该站点,被重定向到该站点的HTTPS版本并查看该站点。然而,在控制台中,我收到关于混合内容的错误,挂锁屏蔽显示为黄色或红色,而不是所需的绿色

有一些文件存在问题,例如,我知道我可以手动更改URL以使用
https
,而不是
http
。据我所知,我可以使用将URL更改为以下内容,这将简单地将链接调整为当前使用的协议:

<img src="//www.example.com/image.jpg" />
然而,我正在尝试使用
htaccess
(我确信我以前做过这件事,但我的代码片段对我不起作用)一次性修复所有这些问题

我曾尝试使用两个主要的代码片段将所有内容强制通过
https
,第一个是:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

#These Lines to force HTTPS
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

然而,两者似乎都不能解决我的问题。作为预防措施,我已在每次更改后重新启动
httpd
服务,即使
htaccess
更改不需要重新启动,但情况仍然相同。有人能给我指出正确的方向吗?

最简单的解决方案是手动更换所有链接。使用下面的解决方案可以节省您的时间,而且非常简单

其思想是删除所有协议(HTTP和HTTPS),让它们使用协议相对URL

我们可以使用
index.php

<?php
//this lined added here
ob_start();
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );

//and these lines also 
$output = ob_get_contents();
ob_end_clean();

$output = str_replace(array("https://", "http://"), "//", $output);
echo str_replace('http:\/\/', "\/\/", $output);

RewriteRule^/(.*)
更改为
RewriteRule^(.*)
如果这是在您的htaccess文件中。@hjpotter92非常感谢您的响应,我已将这些行更改为以下
。#这些行将强制HTTPS RewriteCond%{SERVER\u PORT}^443$RewriteRule^(.*)https://%{HTTP_HOST}/$1[NC,R=301,L]
不幸的是,它仍然不能发挥作用。如果它有任何帮助,您可以使用此桌面应用程序快速跟踪混合内容问题,或者请求他们提供报告:使用
/
而不是协议无疑是一种方法。我还没有见过这样的解决方案,非常有趣。@TheHumbleRat:我在使用Wordpress超级现金插件时也解决了这个问题,如果您使用了它,请通知我,我将与您分享解决方案。可行的解决方案,但不完美。例如,如果网站包含指向其他网站的链接,脚本也会将其更改为https。@electroid:您可以使用它来仅替换您的域。@Akam是否有办法对
domain.com/wp admin/*
执行相同的操作?试图用同样的技巧编辑
/wp admin/index.php
,但一点运气都没有
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

#These Lines to force HTTPS
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
<?php
//this lined added here
ob_start();
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require( dirname( __FILE__ ) . '/wp-blog-header.php' );

//and these lines also 
$output = ob_get_contents();
ob_end_clean();

$output = str_replace(array("https://", "http://"), "//", $output);
echo str_replace('http:\/\/', "\/\/", $output);
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">