【问题标题】:URL Rewrite to change querystring caseURL 重写以更改查询字符串大小写
【发布时间】:2013-11-16 12:39:11
【问题描述】:

我希望在我的 web.config 中设置一个 URL 重写规则,该规则将修改以下 URL:

/detail.aspx?aID=164&mode=t

致(见aid的情况):

/detail.aspx?aid=164&mode=t

请问有人可以帮我解决这个问题吗?这里唯一要提到的另一件事是,如果末尾没有 mode 参数并且无论 aid 参数在查询字符串中出现的顺序如何,该规则仍然有效。

编辑 1

我发现本指南将整个 URL 重写为小写。这对我有用,只有接受的解决方案似乎忽略了查询字符串值。

How to display URL in lower case?

编辑 2

我现在使用以下命令在找到大写字符时发出 301 重定向。接受的答案解决了原始问题,但此解决方案适用于完整的 URI、域、路径和查询字符串。

        '301 REDIRECT ON UPPERCASE URIS
        Dim fullUri As String = Request.Url.AbsoluteUri
        If fullUri.Any(Function(c) Char.IsUpper(c)) Then
            Response.RedirectPermanent(fullUri.ToLower)
        End If

【问题讨论】:

    标签: asp.net url-rewriting rewrite url-rewrite-module


    【解决方案1】:

    编辑: 你是对的,没有意识到这是同一页。 您需要添加另一个条件。

     <rule name="URL Lower" enabled="true" stopProcessing="true">
          <match url="^(detail.aspx?)(.*)" />                        
          <conditions trackAllCaptures="true">
              <add input="{QUERY_STRING}" pattern="(.*)" />
              <add input="{QUERY_STRING}" pattern="([A-Z]+)" ignoreCase="false" />
          </conditions>
          <action type="Redirect" url="detail.aspx?{ToLower:{C:1}}" appendQueryString="false" />
     </rule>
    

    例子:

    /detail.aspx?aID=164&mode=t 转换为 /detail.aspx?aid=164&mode=t

    并且 /detail.aspx?aid=164&mode=t 由于第二条规则而被忽略。

    【讨论】:

    • 这会创建一个递归重定向循环 :(
    • 完美运行并被接受,因为它回答了原始问题。尽管现在我坚持使用 EDIT 2 中的代码,因为它解决了完整 URi 的情况。
    猜你喜欢
    • 2011-08-02
    • 2012-01-18
    • 1970-01-01
    • 2011-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多