在Google Chrome上浏览网络时,您会看到一些标有“不安全”的网页。

在Google Chrome中不安全警告,标记没有SSL证书的HTTP网站

这意味着这些域没有SSL证书installed and therefore do not encrypt information shared between a visitor’s browser and the site. In addition to Google Chrome’s warning, you can identify these sites by the http:// at the beginning of their URLs.

Chrome开始了marking these HTTP sites as non-secure in January 2017with the goal of helping users browse the web safely. Because it helps keep sensitive information like passwords and payment information safe, visitors feel safer on sites that are encrypted with SSL.

搜索engines and consumers alike show preference to HTTPS sites, more of the internet has become encrypted. In fact, there are超过1.55亿个网站今天在互联网上获得SSL证书。去年的这个时候,只有大约1.38亿。

要加入互联网上越来越多的加密网站,您可以在您的WordPress网站。让我们看一下下面这样做的两种方法。

Grow Your Business With HubSpot's Tools for WordPress Websites

如何将https强加于wordpress

在WordPress上强迫HTTPS相对容易。启动,安装或在您的网站上启用SSL证书。最多WordPress托管提供商在他们的计划中包含SSL证书,因此您只需要与主机联系以要求他们安装它。如果您的托管计划不包含SSL证书,则可以免费从诸如证书授权机构中获得Let’s Encrypt

有关免费或低成本证书机构的深入比较,请退房如何获得SSL证书[+10最佳免费SSL]

安装了SSL证书后,您需要配置网站,以便将安全URL与HTTPS一起使用而不是HTTP。让我们看一下您可以在下面尝试的两种方法。

选项1:WordPress插件强制https

如果您是没有编码经验的初学者,则可以使用WordPress插件to force your site to load securely over HTTPS. There are several plugins designed for this purpose.

One of the most highly rated and downloaded isReally Simple SSL。让我们通过下面的此插件在WordPress上强迫HTTPS的过程。

  • 登录您的WordPress仪表板,然后转到Plugins>添新
  • 搜索真正简单的SSL插件。

在WordPress仪表板中安装并激活真正简单的SSL插件

  • 点击theInstall Now启用buttons.
  • 单击标记的按钮继续,激活SSL!

单击标记的按钮继续,激活SSL!in Really Simple SSL plugin settings

SSL现在将在您的网站上激活,但是您将“分配”一些任务。这些不一定是必需的,因此您可以将它们解雇或开放并完成其他时间。

真正简单的SSL插件的剩余任务以完成强迫https在WordPress中的过程

尽管此插件方法简单快捷,但它被认为是临时解决方案,因为它不会在WordPress数据库中使用HTTP更新URL。要在WordPress站点上永久强制HTTPS,请尝试以下方法。

选项2:强制使用WordPress上使用HTACCESS的HTTPS

在WordPress网站上强制HTTPS的另一种方法需要您编辑.htaccess文件。尽管对于很少有技术经验的初学者或用户来说,这种方法将更加困难,但与使用插件相比,这是一个更有效和永久的解决方案。让我们浏览以下过程。

步骤1:更新您的常规设置。

  • 登录to your WordPress dashboard ang go toSettings>一般的
  • 向下滚动到WordPress和站点URL地址字段,然后用HTTP替换HTTP。

用WordPress仪表板中的WordPress和站点URL地址替换HTTP

  • 点击the保存更改页面底部的按钮。

您将自动从仪表板上记录,必须重新登录。

Step 2: Set up 301 redirects in your .htaccess file.

接下来,您需要设置301重定向from the HTTP version of your web pages to the HTTPS version. This will ensure that any visitor — even one who types in an HTTP URL into their browser’s address bar — will be redirected to HTTPS. This will also avoid the WordPress HTTP “not working” error. Here are the steps:

  • 登录到您的托管帐户的控制面板。
  • 打开文件管理器

单击托管帐户控制面板中的文件管理器,以开始在WordPress中强制HTTPS的过程

图像源

  • 在屏幕左侧的导航菜单中,单击public_html文件夹。打开标有“ WordPress”的文件夹。

点击wordpress folder in hosting account's control panel to begin process of forcing HTTPs in WordPress

图像源

  • 查找.htaccess文件,然后右键单击以进行编辑。
  • 在读取#开始WordPress的行之前添加以下代码。


RewriteEngine On
重新WriteCond%{https}!= on
重写 ^(。*)$ https://%{http_host}%{request_uri} [l,r = 301,ne]
Header always set Content-Security-Policy "upgrade-insecure-requests;"

Step 3: Resolve the “Mixed Content” error message.

通过完成上面的两个步骤,将设置您的网站以使用HTTPS,但是您必须完成一些其他步骤,以防止“混合内容”错误出现在您的网站上。这是一个错误消息在Chrome中显示的示例。

混合内容错误消息在WordPress网站上显示的,该网站没有强制其数据库中的HTTPS

图像源

该错误是由文件(例如图像,脚本和您的主题样式表)引起的,这些文件仍在HTTP上加载。为了防止或解决此错误,请按照以下步骤操作。

  • Install and activate the更好的搜索更换plugin.
  • 点击Tools>更好的搜索更换
  • In the field labelled “Search,” type in your domain name with HTTP.
  • 在标记为“替换”的字段中,用https在域名中键入。

Configure Better Search Replace plugin settings to force HTTPS in WordPress dashboard

  • Select all your database tables below so the plugin searches and replaces every HTTP URL in your database.

在更好的搜索替换插件设置页面中选择所有数据库表,以强制WordPress仪表板中的HTTPS

  • 取消选中旁边的盒子作为干式运行?
  • 点击the运行搜索/替换button.

现在,该插件将从HTTP开始搜索您的WordPress数据库以搜索URL,并以HTTPS开头的URL替换它们。这需要多长时间取决于您的WordPress数据库大小。

If you complete the steps above and are still seeing the mixed content error on your site, then the problem might be yourWordPress主题or plugins. In that case, use your browser’s Inspect Tool to identify the mixed content items. If a stylesheet is mentioned, then you might need to find and replace any URLS with HTTP in your WordPress theme files manually.

如果问题是插件,则不应编辑插件文件。相反,您需要与插件作者联系以要求他们修复它。否则,您需要找到一个替代插件。

Add Your HTTPS Website to Google Search Console

要完成在WordPress网站上强迫HTTP的过程,您必须将您的域名添加为HTTPS作为新属性Google搜索控制台。This — in addition to the 301 redirects set up in the plugin or htaccess method above — will ensure Google transfers your search rankings to the HTTPS version of your site. Below are the steps to follow.

登录to your Google Search Console account.

单击搜索框,然后单击添加属性button at the bottom of the menu.

点击add property in Google Search Console to add HTTPS site

图像源

A popup box will appear. Select网站从下拉菜单,并使用HTTPS输入域名。

You’ll now be asked to verify your site. There are several ways to do so, including using your domain name provider or Google Analytics account. Simply select the verification method you’re most comfortable with and follow the instructions provided by Google.

在Google搜索控制台中输入URL前缀以验证HTTPS网站

图像源

验证网站后,您将可以在Google搜索控制台帐户中查看网站的HTTP和HTTPS版本的报告。

创造更安全的浏览体验

搜索engines and online consumers show an increasing preference for HTTPS sites, it’s important that you install an SSL certificate on your WordPress site if you haven’t already. Once you do, you can use either of the methods above to redirect any visitors from the HTTP to the HTTPS version of your site. This will not only help make your website safer to browse — it will also help make the Internet safer more broadly.

使用WordPress网站上的HubSpot工具,并在不处理代码的情况下连接两个平台。点击这里了解更多。

使用WordPress网站上的HubSpot工具,并在不处理代码的情况下连接两个平台。点击这里了解更多。

最初出版于2021年3月9日7:00:00 AM,更新于2021年3月9日

话题:

WordPress网站