【问题标题】:Creating a IIS Url Rewrite/Redirect创建 IIS URL 重写/重定向
【发布时间】:2016-10-10 19:32:07
【问题描述】:

我正在努力让 url 重写/重定向以在 IIS 中工作。我已经安装了 url rewrite 模块并且所有的规则都没有做任何事情。这是场景,我们希望所有生成报告的 Web 请求都被推送到辅助服务器,这样它就不会损害主框。生成报告的网络请求如下所示:

http://mywebaddress/api/Actionname=GenerateReport&param=123

所以我想做某种类型的正则表达式检查以查找任何包含“GenerateReport”的网络请求并将其重定向到类似的内容:

http://mywebaddressofsecondserver/api/Actionname=GenerateReport&param=123

关于重定向/重写将如何实现这一点的任何想法?

【问题讨论】:

    标签: redirect mod-rewrite iis url-rewriting


    【解决方案1】:

    谢谢,贾斯汀·伊尔曼,

    你的回答解决了我获取方法的问题

    http://mywebaddress/api/Param/Action1 http://localserverwithport/api/Param/Action1

    但是对于下面的 Post 方法,它仍然给出 404 not found

    http://mywebaddress/api/Param/PostAction2 http://localserverwithport/api/Param/PostAction2

    帖子参数为: {"Param1":"James","Param2":"jani"}

    我的实现是

    '<system.webServer>
            <rewrite>
                <rules>            
                   <rule name="Rewrite Rule1" >
                        <match url="^(.*)" />                    
                        <action type="Redirect" url="http://localserverwithport/{R:1}" />
                    </rule>             
                </rules>
            </rewrite>
    </system.webServer>'
    

    【讨论】:

      【解决方案2】:

      您需要检查REQUEST_URI 是否包含Actionname=GenerateReport
      如果是这样,您会将其重定向到 其他等效的网络服务器 url

      转换为 IIS 重写规则,它看起来像这样

      <rule name="Delegate report generation" stopProcessing="true">
         <match url="^(.*)$" />
         <conditions>
            <add input="{REQUEST_URI}" pattern="Actionname=GenerateReport" />
         </conditions>
         <action type="Redirect" url="http://mywebaddressofsecondserver/{R:1}" />
      </rule>
      

      【讨论】:

        猜你喜欢
        • 2019-02-11
        • 1970-01-01
        • 1970-01-01
        • 2015-01-29
        • 2016-06-06
        • 1970-01-01
        • 2023-03-04
        • 2017-02-13
        • 2012-05-27
        相关资源
        最近更新 更多