【问题标题】:regular expression for urls to rewrite用于重写 url 的正则表达式
【发布时间】:2017-12-13 15:39:41
【问题描述】:

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

所以
案例一:https://example.com/test
案例二: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】:

    你的规则应该是这样的:

    <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} 的字符串

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-03
      相关资源
      最近更新 更多