iis - 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>
没有改进(谷歌上的重定向检查器仍然不会触发重定向集)
解决方案
根据您的 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>
推荐阅读
- javascript - Mongoose:E11000 重复键改变返回消息的类型以防出错
- r - 二元逻辑回归输出
- javascript - 如何为此对象编写打字稿声明文件?
- python-3.x - 为什么读取上传文件和读取本地文件会产生不同的结果?
- laravel - 如何在 Laravel 中将此反序列化数据显示到刀片
- javascript - 传入函数参数而不调用函数
- python - subprocess.call() 挂起。“os.waitpid(self.pid,wait_flags)”
- c# - 以编程方式更改域名解析为特定查询的 IP 地址
- python - 将来自多个客户端的数据保存到一个文件时出现问题。TCP 蟒蛇
- amazon-web-services - 重新部署到 EC2 实例后,应用程序没有变化