【问题标题】:Issue when redirecting a folder using IIS url rewrite使用 IIS url 重写重定向文件夹时出现问题
【发布时间】:2013-12-11 02:58:00
【问题描述】:

使用 Url Rewrite,我正在尝试将 /foo_bar/* 重定向到 /foo/*。我试过这个:

<rule name="Redirect foo_bar to foo" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_URL}" pattern="^/foo_bar/(.*)" />
    </conditions>
    <action type="Redirect" url="/foo/{R:1}" />
</rule>

但这只是重定向到 /foo/foo_bar/*。我哪里错了?

【问题讨论】:

    标签: iis url-rewriting web-config


    【解决方案1】:

    问题在于比赛。我认为你甚至不需要一个条件。只需尝试以下方法:

    <rule name="Redirect foo_bar to foo" stopProcessing="true">
        <match url=".*/foo_bar/(.*)" />
        <action type="Redirect" url="/foo/{R:1}" />
    </rule>
    

    【讨论】:

    • 太好了,谢谢!知道为什么我不能以我尝试的方式匹配吗?
    • 问题是 url 的拆分发生在匹配而不是条件中。当您拆分整个 URL 时,{R:1} 变量将具有整个 URL。您可能想尝试使用 gui 进行 URL 重写。您可以测试输入...
    猜你喜欢
    • 2016-06-06
    • 2017-02-13
    • 2013-10-16
    • 1970-01-01
    • 2016-05-03
    • 2012-05-23
    • 2014-02-19
    • 1970-01-01
    • 2019-02-11
    相关资源
    最近更新 更多