首页 > 解决方案 > IIS 中的重定向规则不适用

问题描述

我有以下问题:

我想让确切 url 的用户重定向到另一个。注意:我的 URL 会立即下载文件。

我想要的是让文件转发到另一个文件(它需要下载我重定向到的文件)。

我的规则:

<rule name="File" patternSyntax="ExactMatch" stopProcessing="true">
                    <match url="https://SITE.be/download/DownloadFile?id=138999" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{URL}" pattern="https://SITE.be/download/DownloadFile?id=138999" />
                        <add input="{QUERY_STRING}" pattern="https://SITE.be/download/DownloadFile?id=138999" />
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" />
                    </conditions>
                    <action type="Redirect" url="https://SITE.be/download/DownloadFile?id=138111" appendQueryString="false" />
                </rule>

我的规则不起作用,它不会重定向它,当我检查“URL 重定向检查器”时,它提到 URL 上没有设置重定向。

我究竟做错了什么?

编辑:

我试过了:

<rule name="File" stopProcessing="true">
            <match url="download/DownloadFile?id=138999" />
            <conditions logicalGrouping="MatchAny">
               <add input="{HTTP_HOST}" pattern="^site.be$" />
            </conditions>
            <action type="Redirect" url="https://site.be/download/DownloadFile?id=138111" appendQueryString="false" />
        </rule>

没有改进(谷歌上的重定向检查器仍然不会触发重定向集)

标签: iisurl-rewritingurl-redirection

解决方案


根据您的 iis 重写代码,我发现匹配 url 部分有问题。这部分只能匹配 [download/DownloadFile] 而不是查询字符串。如果我们要检查查询字符串 id,我们应该使用 url 重写条件。

更多细节,你可以参考下面的 url 重写规则。

<rule name="File" stopProcessing="true">
            <match url="download/DownloadFile" />
            <conditions logicalGrouping="MatchAll">
                        <add input="{QUERY_STRING}" pattern="id=138999" />
                         <add input="{HTTP_HOST}" pattern="^site.be$" />
            </conditions>
            <action type="Redirect" url="https://site.be/download/DownloadFile?id=138111" appendQueryString="false" />
        </rule>

或者

<rule name="File" stopProcessing="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_HOST}" pattern="sitebe" />
                        <add input="{REQUEST_URI}" pattern="download/DownloadFile\?id=138999" />
            </conditions>
            <action type="Redirect" url="https://site.be/download/DownloadFile?id=138111" appendQueryString="false" />
        </rule>

推荐阅读