IIS 7从HTTP到HTTPS的redirect失败,并在URL中带有&符号

Windows Server 2008 R2 SP1上的IIS 7

我在web.config中添加了以下规则,将所有传入请求redirect到HTTPS

<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> 

当&符号(&)出现在URL或文件名中时,它将失败。 我已经看过一些提供的解决scheme,并且对通过registry允许特殊字符不感兴趣。 有没有一种方法来执行重写编码与&或%26之前的redirect规则的&符号? HTTPSredirect规则是否使用原始URL或新重写/编码的版本?

您需要使用[NE]参数

<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" [NE] />