IIS重写规则-如果路径没有查询字符串



如何编写IIS重写规则if path does not have query string and any capital letter exists in path then redirect to same path with lower case

例如
http://localhost:62871/Second.aspx/Test?X=Y
重定向到:http://localhost:62871/second.aspx/test?X=Y

以下规则有效,但它也降低了查询字符串的大小写:

<rewrite>
<rules>
<rule name="LowerCaseRule1" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>
</rules>
</rewrite>

变量URL包含整个url,因此ToLower是整个url的小写。

为了获得所需的行为,您需要从多个服务器变量手动创建action的url。

可用的变量包括{HTTP_HOST}{PATH_INFO}{QUERY_STRING},然后可以将小写函数应用于所需的任何变量。

创建最终url时,还需要在变量之间包含分隔符:/?,以获得有效的url。

有关变量的快速概述,请参阅本页:https://weblogs.asp.net/owscott/url-parts-available-to-url-rewrite-rules

请参阅此处获取完整的重写模块文档:https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

最新更新