Url rewriting URL重写-重定向到其他端口并使用映射更改URL
我想重写URL以重定向到不同的端口,基于HTTP_URL,同时保留URL和查询字符串的其余部分(如果指定)。 例如,Url rewriting URL重写-重定向到其他端口并使用映射更改URL,url-rewriting,iis-7.5,Url Rewriting,Iis 7.5,我想重写URL以重定向到不同的端口,基于HTTP_URL,同时保留URL和查询字符串的其余部分(如果指定)。 例如, http://host/john/page.aspx应重定向到http://host:1900/page.aspx, http://host/paul/anotherpage.aspx?query至http://host:1901/anotherpage.aspx?query 和http://host/ringo至http://host:1902/ 我已经为每个允许的端口添加了一
http://host/john/page.aspx
应重定向到http://host:1900/page.aspx,
http://host/paul/anotherpage.aspx?query
至http://host:1901/anotherpage.aspx?query
和
http://host/ringo
至http://host:1902/
我已经为每个允许的端口添加了一系列规则,但看起来效率和可管理性都不高。
我试图使用map(即john->1900,paul->1901),但不知道如何组合所需的URL。
有什么建议吗?需要一些努力才能使它工作,但回头看,解决方案非常简单和优雅
<rewrite>
<rules>
<clear />
<rule name="Redirect known names to ports" stopProcessing="true">
<match url=".*" />
<conditions trackAllCaptures="true">
<add input="{REQUEST_URI}" pattern="/(.*?)/(.*)" />
<add input="{NameToPort:{C:1}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}:{C:3}/{C:2}" appendQueryString="false" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="NameToPort">
<add key="john" value="1900" />
<add key="paul" value="1901" />
<add key="ringo" value="1902" />
</rewriteMap>
</rewriteMaps>
</rewrite>
让我知道这是否是你要找的