要重写的URL的正则表达式

问题描述 投票:0回答:1

我需要在IIS中编写重定向规则,重定向到https://example.com/xml

所以 案例1:https://example.com/test 案例2:https://example.com/[country-lang-token]/test

(例如https://example.com/en-us/testhttps://example.com/fr-fr/test

应该重定向到https://example.com/xml

我知道如何编写重写规则但由于正则表达式而停滞不前。

url-rewriting iis-7 iis-8
1个回答
1
投票

你的规则应该是这样的:

<rule name="Redirect to xml" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAny">
        <add input="{REQUEST_URI}" pattern="^/test$" />
        <add input="{REQUEST_URI}" pattern="^/\w{2}-\w{2}/test$" />
    </conditions>
    <action type="Redirect" url="/xml" />
</rule>

第一个条件是案例1 url https://example.com/test第二个条件是案例2 https://example.com/[country-lang-token]/test其中[country-lang-token]是字符串格式{two_letters}-{two_letters}

© www.soinside.com 2019 - 2024. All rights reserved.