如何设置iis7.0下http跳转到https

2015-12-22 22:26:00 9026

在安装证书完成后,要想实现输入域名自动跳转到https,我们还需要通过添加代码才能达到效果。不同的操作系统的设置也是不一样的。

1.Linux主机

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

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

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

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

RewriteEngine On

RewriteCond %{SERVER_PORT} 80

RewriteCond %{REQUEST_URI} somefolder

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

2.Windows主机

Windows主机需要在web.config文件中,然后在该文件里面添加下面代码:

<?xml version="1.0" encoding="UTF-8"?>

<configuration>

    <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" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />

</rule>

     </rules> 

</rewrite>

    </system.webServer>

</configuration>

3.nginx web服务器的设置

server { 

    listen  192.168.1.111:80;  

    server_name test.com;   

    rewrite ^(.*)$  https://$host$1 permanent;  

提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: