安装SSL证书后实现http自动跳转到https

ByWhat'sUs

安装SSL证书后实现http自动跳转到https

GoDaddy主机和Hostus的vps主机

Linux主机

如果使用的是Linux主机,需要在你的网站根目录下的.htaccess文件(没有需要创建一个)中添加下面代码然后保存即可:

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

RewriteRule ^(.*)$ https://www.xxx.com/$1 [R,L]

(你网站的域名替换上面的xxx.com)

 

当然,如果想指定某一个文件使用https,则添加一下代码(此时.htaccess文件需要放在你指定的文件夹中):

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

RewriteCond %{REQUEST_URI} somefolder

RewriteRule ^(.*)$ https://www.xxx.com/somefolder/$1 [R,L]

(你网站的域名替换上面的xxx.com)

 

Windows主机

GoDaddy的Windows主机需要在web.config文件中(没有需要创建),然后在该文件里面添加下面代码:

<rule name=”HTTP to HTTPS redirect” stopProcessing=”true”>

<match url=”(.*)” />

<conditions>

<add input=”{HTTPS}” pattern=”off” ignoreCase=”true” />

</conditions>

<action type=”Redirect” redirectType=”Found” url=”https://{HTTP_HOST}/{R:1}” />

</rule>

通过以上方式便可以实现http自动跳转到https

参考: https://blog.csdn.net/aerchi/article/details/72899826

About the author

What'sUs administrator

Leave a Reply

PHP Code Snippets Powered By : XYZScripts.com