iis - IIS - 端口重定向 - 重写模块 - Web.Config 文件
问题描述
我正在尝试创建一个适当的 web.config 文件来重定向最终用户,以向请求添加端口。
例如,输入 http://subscribe.service.com/lists/index.html 的任何最终用户都将被重定向到http://subscribe.service.com:3000/lists/index.html,这样无论调用什么请求它将添加到其中:3000。
下面提供了我正在使用的代码示例。在验证测试中,它似乎可以按我的意愿工作。实际上,当我访问物理网站时,什么都没有发生。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="false" destination="" childOnly="true" httpResponseStatus="Permanent" />
<rewrite>
<rules>
<rule name="3000 Port Redirect" enabled="true" stopProcessing="true">
<match url="http:/(.*)com" />
<conditions>
<add input="{HTTP_HOST}" pattern="\.com(.*)" />
</conditions>
<action type="Redirect" url="{R:0}:3000{C:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
解决方案
正如 Lex Li 的文章所提到的,url rewrite model partern 与域不匹配。这意味着 IIS 使用 lists/index.html 来匹配“http://(.*)com”规则。所以你会发现你的规则不起作用。
我建议你可以尝试使用下面的 url 重写规则。
<rule name="rewrite to 81 port" enabled="true">
<match url="(.*)" />
<action type="Redirect" url=" http://subscribe.service.com:3000/{R:0}" appendQueryString="true"/>
</rule>
然后它会很好地工作。
推荐阅读
- ios - 捕获音频样本以将音频实时推送到服务器
- encryption - 为什么 GitHub 需要 **only** 公钥才能使用 ssh?
- wordpress - 如何转义棱镜中的尖括号(“<”,“>”)?
- azure - java.lang.IllegalStateException:无法配置 KeyVault 属性源
- javascript - 使用 Laravel 项目托管后 HighCharts 不显示图形
- rest - 使用 deltas 与 Sockets 轮询
- swift - 如何将文件中的文本导入数组?
- python - 在pygame中的数组支持网格中交换颜色的问题
- java - 将波斯语中的数值作为字符串类型更改为拉丁语
- javascript - 返回事件的承诺