gpt4 book ai didi

url-rewriting - URL 重写 - 重定向到不同的端口并使用映射更改 URL

转载 作者:行者123 更新时间:2023-12-05 08:59:35 28 4
gpt4 key购买 nike

我想基于 HTTP_URL 重写 URL 以重定向到不同的端口,同时保留其余的 URL 和查询字符串(如果指定)。例如,
http://host/john/page.aspx 应该重定向到 http://host:1900/page.aspx,
http://host/paul/anotherpage.aspx?queryhttp://host:1901/anotherpage.aspx?query
http://host/ringohttp://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>

如果这就是您要找的,请告诉我。

关于url-rewriting - URL 重写 - 重定向到不同的端口并使用映射更改 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13189505/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com