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