URL Rewrite to change querystring case

匆匆过客 提交于 2019-12-11 11:39:40

问题


I am looking to setup a URL rewrite rule in my web.config that will modify the following URL:

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

To (see case of aid):

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

Please can anyone assist me with this? The only other thing to mention here is that the rule should still work if there is no mode parameter at the end and irrespective of what order the aid parameter appears in the querystring.

EDIT 1

I found this guide which rewrites the whole URL to lowercase. This would work for me only the accepted solution seems to ignore the query string values.

How to display URL in lower case?

EDIT 2

I'm now using the following to issue a 301 redirect when uppercase characters are found. the accepted answer addresses the original question but this solution works on the full URI, domain, path and querystring.

        '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

回答1:


EDIT: You are right, did not realize it was same page. You need to add another condition.

 <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>

Examples:

/detail.aspx?aID=164&mode=t converts to /detail.aspx?aid=164&mode=t

and /detail.aspx?aid=164&mode=t is ignored because of second rule.



来源:https://stackoverflow.com/questions/20018553/url-rewrite-to-change-querystring-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!