创建IIS URL重写/重定向

时间:2016-06-09 23:50:23

标签: redirect mod-rewrite iis url-rewriting

我努力让网址重写/重定向在IIS中运行。我已经安装了url rewrite模块,并且所有规则都无法执行任何操作。在这种情况下,我们希望生成报告的所有Web请求都被推送到辅助服务器,这样它就不会损害主框。生成报告的Web请求如下所示:

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

所以我想要做一些类型的正则表达式检查,找到任何有" GenerateReport"在其中并将其重定向到类似:

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

有关重定向/重写如何实现的任何想法?

2 个答案:

答案 0 :(得分:0)

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

转换为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>

答案 1 :(得分:0)

谢谢,贾斯汀·欧曼,

您的答案解决了我获取方法的问题

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

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

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

Post参数为: {“ 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>'