IIS重写-仅将一个主机名的根目录重定向到HTTPS? [英] IIS Rewrite - Redirecting only the root of one hostname to HTTPS?

查看:58
本文介绍了IIS重写-仅将一个主机名的根目录重定向到HTTPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试仅将输入http://site.domain.com的用户重定向到https://site.domain.com

I'm trying to redirect only user who enters http ://site.domain.com to https ://site.domain.com

任何其他http页面都不应重定向到https(例如: http://site.domain.com/page2 )

Any other http page should not redirect to https (ex: http://site.domain.com/page2)

我尝试过这种方法:

    <rewrite>
        <rules>
            <rule name="Redirect to HTTPS" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
                <match url="^$" ignoreCase="true" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{HTTPS}" pattern="^OFF$" />
                    <add input="{HTTP_HOST}" pattern="^site\.domain\.com$" />
                </conditions>
                <action type="Redirect" url="https://site.domain.com/" appendQueryString="false" redirectType="SeeOther" />
            </rule>
        </rules>
    </rewrite>

或者这个:

    <rewrite>
        <rules>
            <rule name="Redirect to HTTPS" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
                <match url="(.*)" ignoreCase="true" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{HTTPS}" pattern="^OFF$" />
                    <add input="{HTTP_HOST}" pattern="^site\.domain\.com$" />
                    <add input="{PATH_INFO}" pattern="^$" />
                </conditions>
                <action type="Redirect" url="https://site.domain.com/" appendQueryString="false" redirectType="SeeOther" />
            </rule>
        </rules>
    </rewrite>

但是没有重定向发生.我想念什么吗?

But no redirect occurs. Am I missing something?

推荐答案

但是我会尝试使用^ $并尝试以下变体:

But I would try to stick with ^$ and try this variant:

<rewrite>
    <rules>
        <rule name="Redirect to HTTPS" stopProcessing="false">
            <match url="^$" />
            <conditions>
                <add input="{HTTPS}" pattern="off" ignoreCase="true" />
            </conditions>
            <action type="Redirect" url="https://{SERVER_NAME}/" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>

这篇关于IIS重写-仅将一个主机名的根目录重定向到HTTPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆