URL重写不保持完整路径

时间:2017-09-20 18:40:59

标签: url url-rewrite-module

我尝试使用 IIS 8 的URL重写模块来确保所有连接都是https。我无法弄清楚的是如何维持规则的完整路径。我是新手,所以希望这是一个简单的解决方法。

我会转到这样的页面:https://xyz.domain.com/mypath/default.aspx

删除'来自' https',我被重定向到https://xyz.domain.com/default.aspxmypath路径消失了。我需要保持这个。

这是webconfig条目:

    <rewrite>
    <rules>
        <rule name="Force http to https" stopProcessing="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAny">
                <add input="{HTTPS}" pattern="^OFF$" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
        </rule>
    </rules>
</rewrite>

2 个答案:

答案 0 :(得分:0)

请改为尝试:

<!-- Require HTTPS -->
<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>

答案 1 :(得分:0)

在网上跟随示例后,我遇到了同样的问题。我将重定向URL更改为https://{HTTP_HOST}/{REQUEST_URI},并在重定向请求中保留了完整URL。

有关参考,请参见在线文档URL Rewrite Module Configuration Reference