[英]Creating a IIS Url Rewrite/Redirect
Im struggling to get a url rewrite/redirect to work in IIS.我正在努力让 url 重写/重定向在 IIS 中工作。 I've installed the url rewrite module and all the rules fail to do anything.
我已经安装了 url 重写模块,但所有规则都无法执行任何操作。 Here is the scenario, we want all web requests which generate a report to be pushed off to a secondary server so it doesn't harm the main box.
这是一个场景,我们希望所有生成报告的 Web 请求都被推送到辅助服务器,这样它就不会损害主框。 The web requests that generate reports look something like this:
生成报告的 Web 请求如下所示:
http://mywebaddress/api/Actionname=GenerateReport¶m=123 http://mywebaddress/api/Actionname=GenerateReport¶m=123
So im wanting to do some type of regex check on finding any web requests that have "GenerateReport" in it and redirect it to something like:因此,我想做某种类型的正则表达式检查,以查找其中包含“GenerateReport”的任何 Web 请求并将其重定向到以下内容:
http://mywebaddressofsecondserver/api/Actionname=GenerateReport¶m=123 http://mywebaddressofsecondserver/api/Actionname=GenerateReport¶m=123
Any ideas on how the redirect/rewrite would go for this?关于重定向/重写将如何进行的任何想法?
You need to check if REQUEST_URI
contains Actionname=GenerateReport
.您需要检查
REQUEST_URI
包含Actionname=GenerateReport
。
If so, you'll redirect it to other webserver url equivalent .如果是这样,您会将其重定向到其他网络服务器 url 等效项。
Translated to an IIS rewrite rule, it would look like this转换为 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>
Thanks, Justin Iurman,谢谢,贾斯汀·欧曼,
Your answer solved my issue of getting methods您的回答解决了我获取方法的问题
http://mywebaddress/api/Param/Action1 http://localserverwithport/api/Param/Action1 http://mywebaddress/api/Param/Action1 http://localserverwithport/api/Param/Action1
but for below Post methods it's still giving 404 not found但是对于下面的 Post 方法,它仍然给出 404 not found
http://mywebaddress/api/Param/PostAction2 http://localserverwithport/api/Param/PostAction2 http://mywebaddress/api/Param/PostAction2 http://localserverwithport/api/Param/PostAction2
Post parameters are: {"Param1":"James","Param2":"jani"}帖子参数为:{"Param1":"James","Param2":"jani"}
My implementation is我的实现是
'<system.webServer>
<rewrite>
<rules>
<rule name="Rewrite Rule1" >
<match url="^(.*)" />
<action type="Redirect" url="http://localserverwithport/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.