【问题标题】:IIS - Port Redirection - Rewrite Module - Web.Config FileIIS - 端口重定向 - 重写模块 - Web.Config 文件
【发布时间】:2019-01-24 20:00:51
【问题描述】:

我正在尝试创建一个适当的 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>

【问题讨论】:

标签: iis module url-rewriting web-config


【解决方案1】:

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

然后它会很好地工作。

【讨论】:

    猜你喜欢
    • 2013-04-23
    • 1970-01-01
    • 2016-04-26
    • 2013-12-15
    • 2011-01-16
    • 1970-01-01
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    相关资源
    最近更新 更多