使用 .htaccess 和 web.config 强制网站进行 HTTPS (SSL) 连接
即使您在网站上安装了 Let's Encrypt 或付费 SSL 证书,当访问者直接在浏览器中输入您网站的地址时,他们将自动收到过时且不安全的证书。http://可以用协议打开。确保您的网站不会在搜索引擎 (SEO) 中失去价值,并且始终具有安全的绿色锁 (https://为了使用 ) 打开,您必须执行基于服务器的永久重定向(301 重定向)。
方法 1:对于 Linux / Apache / Litespeed 服务器 (.htaccess)
在基于 Linux 的服务器(cPanel、HestiaCP、DirectAdmin 等)上激活重定向 .htaccess 打开文件并将以下代码添加到顶行:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
方法 2:对于 Windows/IIS 服务器 (web.config)
在使用基于 Windows Server 的 Plesk 或 IIS 面板的服务器上,主目录中的目录用于重定向 网络配置 通过打开文件<system.webServer>您应该在标签之间包含以下规则:
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
本文是专门为PvPServer准备的。