[英]Creating a IIS Url Rewrite/Redirect
我正在努力讓 url 重寫/重定向在 IIS 中工作。 我已經安裝了 url 重寫模塊,但所有規則都無法執行任何操作。 這是一個場景,我們希望所有生成報告的 Web 請求都被推送到輔助服務器,這樣它就不會損害主框。 生成報告的 Web 請求如下所示:
http://mywebaddress/api/Actionname=GenerateReport¶m=123
因此,我想做某種類型的正則表達式檢查,以查找其中包含“GenerateReport”的任何 Web 請求並將其重定向到以下內容:
http://mywebaddressofsecondserver/api/Actionname=GenerateReport¶m=123
關於重定向/重寫將如何進行的任何想法?
您需要檢查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>
謝謝,賈斯汀·歐曼,
您的回答解決了我獲取方法的問題
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>'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.