[英]confusion regarding 301 redirect from folder to subfolder in web.config
假設我的api位於此URL http://www.example.net/api/trythis
並且我想重定向到http://www.example.net/api/v1/trythis
,所以將來我可以http://www.example.net/api/v2/trythis
或http://www.example.net/api/v3/trythis
我正在考慮在web.config中執行此操作:
<system.webServer>
<rewrite>
<rules>
<rule name="Root Hit Redirect" stopProcessing="true">
<match url="/api/*" />
<action type="Redirect" url="/api/v1/*" />
</rule>
</rules>
</rewrite>
</system.webServer>
但是,如果有人訪問url /api/v2/trythis or /ap1/v3/trythis
,他們不會重定向到/api/v1/trythis
嗎? 因此,它將打敗版本控制的目的嗎?
根據您的規則,它將導致多個重定向錯誤。 由於“ api / v1”也與“ api”匹配。
要解決此問題,您應該在url重寫規則中設置條件,以避免多個匹配項。
詳細信息,您可以參考以下規則:
<rule name="Root Hit Redirect" stopProcessing="true">
<match url="api/(.*)" />
<action type="Redirect" url="http://yousitedomain.com/api/v1/{R:1}" />
<conditions>
<add input="{PATH_INFO}" pattern="api/v1/(.*)" negate="true"/>
</conditions>
</rule>
如果要避免使用v2,v3,建議您按照上述設置添加多個條件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.