【问题标题】:Rewrite Rule Url To Lowercase Except for Querystring将规则 URL 重写为小写,查询字符串除外
【发布时间】:2014-12-07 14:34:31
【问题描述】:

我的 web.config 文件有基本的重写规则,可以将我的网址转换为小写。

完美,除了一个问题:我在我的电子邮件中传递了区分大小写的令牌,允许用户更改他们的用户名/电子邮件

如何制定一个重写规则,使我的 url 小写,同时让查询字符串保持区分大小写?

例子:

<rule name="Convert to lower case" stopProcessing="true">  
  <match url=".*[A-Z].*" ignoreCase="false" />  
  <action type="Redirect" url="{ToLower:{R:0}}" redirectType="Permanent" />  
</rule>

制作这个网址: http://resources.championscentre.org/ConfirmChangeEmail/abcDEfGhIJKlmn

进入这个: http://resources.championscentre.org/confirmchangeemail/abcdefghijklmn

但必须是: http://resources.championscentre.org/confirmchangeemail/abcDEfGhIJKlmn

【问题讨论】:

    标签: regex asp.net-mvc iis web-config rewrite


    【解决方案1】:

    正则表达式应该是

    ^[\w:\/\.]*\/
    

    \w is [a-zA-Z0-9]

    ^ 锚定开头。

    ^[\w:\/\.]* 计算任何字母数字或/:.

    / 确保最后一个/ 被选中。 (假设您的 URL 不以 / 结尾)

    check the example

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 1970-01-01
    • 2016-08-13
    • 2016-11-01
    • 2015-09-10
    • 2015-01-08
    • 2014-07-23
    相关资源
    最近更新 更多