【问题标题】:How to rewrite part of the URL and then attach the remaining?如何重写部分 URL,然后附加其余部分?
【发布时间】:2015-04-14 19:02:13
【问题描述】:

例如,从 www.example.com/foo/123 重写为 www.example.com/bar/123

在 web.config 我有类似的东西:

<rewriteMap name="TestRM">
<add key="/foo/" value="/bar" />
</rewriteMap>

<rule name="TEST" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{TestRM:{PATH_INFO}}" pattern="(.+)" />
</conditions>
<action type="Redirect" url="http://www.example.com{C:1}" appendQueryString="false" redirectType="Temporary" />
</rule>

有了这个地方,www.example.com/foo 可以重定向到 www.example.com/bar,但不能将 www.example.com/foo/123 重定向到 www.example.com/bar/123

我需要添加什么来附加最后一部分?

【问题讨论】:

    标签: url redirect iis url-rewriting url-redirection


    【解决方案1】:

    您可以使用的策略之一是使用正则表达式并分隔 URL 部分。

    例如网址:www.example.com/foo/123

    正则表达式:^(/foo)(/.*)?将分离出 /foo 和 /123 或 /123/3434/ 或 /foo 之后的任何内容

    然后您可以制作重定向 URL:

    {HTTP-HOST}/bar{R:2}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-26
      • 2020-12-07
      • 2017-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多