我想使用IIS 8.5中的URL重写模块重定向来自http://something.com:112到https://something.com:444(请注意,这些不是标准的http和https端口号)。
我试着使用这个重写规则,但它不起作用:
<rewrite>
<rules>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{SERVER_PORT}" pattern="^444$" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}:444/{R:1}" redirectType="Found" />
</rule>
</rules>
</rewrite>
我在失败请求日志中得到的错误是:
模块名称IIS Web核心通知MAP_REQUEST_HANDLERHttpStatus 404未找到HttpReasonHttpSubStatus 0错误代码系统找不到指定的文件。(0x80070002)
我做错了什么?
我找到了答案,我错误地使用了HTTP_POST,它同时包含SERVER_NAME和HTTP_PORT。相反,我使用了这个动作,它似乎运行得很好:
我还注意到我不需要检查这两种情况。这个实际上做了我需要的,因为我们有一些网站在其他https端口上运行:
<rewrite>
<rules>
<rule name="Redirect to HTTPS on port 444" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{SERVER_NAME}:444/{R:1}" redirectType="Found" />
</rule>
</rules>
</rewrite>