【问题标题】:Regex in Web.config Rewrite Rules for partial lowercase URLWeb.config 中的正则表达式重写部分小写 URL 的规则
【发布时间】:2018-11-19 07:42:16
【问题描述】:

对于 SEO,我希望我的 URL 保持一致,但我不希望这影响任何查询参数。例如: 这些网址:

都应该变成:

但是这个:

应该是:

我有一些东西有时可以解决这个问题:

    <rule name="LowerCaseRule" stopProcessing="true">
      <match url="([A-Z]+)(.*)" ignoreCase="false" />
      <action type="Redirect" url="{ToLower:{R:1}{R:2}}" redirectType="Permanent" />
    </rule>

【问题讨论】:

  • 我收到 ERR_TOO_MANY_REDIRECTS 错误
  • 我暂时没时间测试,不过你可以用conditions做点什么。
  • 看来你应该把ignoreCase="false"改成ignoreCase="true",然后用url="(.*)"url="{ToLower:{R:1}}"就行了。
  • Wiktor 导致相同的 ERR_TOO_MANY_REDIRECTS 错误

标签: c# asp.net regex url-rewriting web-config


【解决方案1】:

感谢John 提供帮助的 cmets,我让它像这样工作:

    <rule name="LowerCaseRule" stopProcessing="true">
      <match url="^(.*?)(\?.*|$)" ignoreCase="false" />
      <conditions logicalGrouping="MatchAny">
        <add input="{SERVER_NAME}" pattern="[A-Z]" ignoreCase="false" />
        <add input="{PATH_INFO}" pattern="[A-Z]" ignoreCase="false" />
      </conditions>
      <action type="Redirect" url="{ToLower:{R:1}}{R:2}" redirectType="Permanent" />
    </rule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-26
    • 2016-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多