Asp.net Url重写为小写不起作用
我的web.config中有以下重写规则。规范规则有效,但小写规则无效 我试着这样测试它:www.mysite.com/UPPERCASE。我本以为url会被转换为www.mysite.com/uppercase,但它仍然是大写的。我做错了什么Asp.net Url重写为小写不起作用,asp.net,url-rewriting,web-config,Asp.net,Url Rewriting,Web Config,我的web.config中有以下重写规则。规范规则有效,但小写规则无效 我试着这样测试它:www.mysite.com/UPPERCASE。我本以为url会被转换为www.mysite.com/uppercase,但它仍然是大写的。我做错了什么 <rewrite xdt:Transform="Insert"> <rules> <rule name="LowerCaseRule" patternSyntax="ExactMatch"> &
<rewrite xdt:Transform="Insert">
<rules>
<rule name="LowerCaseRule" patternSyntax="ExactMatch">
<match url="[A-Z]" ignoreCase="false"/>
<action type="Redirect" url="{ToLower:{URL}}"/>
</rule>
<rule name="CanonicalHostName">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^www.mysite.com$" negate="true" />
</conditions>
<action type="Redirect" url="{MapSSL:{HTTPS}}www.mysite.com/{R:1}" redirectType="Permanent" />
</rule>
</rules>
<rewriteMaps>
<rewriteMap name="MapSSL" defaultValue="OFF">
<add key="ON" value="https://" />
<add key="OFF" value="http://" />
</rewriteMap>
</rewriteMaps>
</rewrite>
您应该从规则
小写字母中删除patternSyntax=“ExactMatch”
,因为在您的情况下,您希望使用正则表达式系统(默认情况下或通过设置patternSyntax=“ECMAScript”
)
所以你的规则应该是:
<rule name="LowerCaseRule">
<match url="[A-Z]" ignoreCase="false"/>
<action type="Redirect" url="{ToLower:{URL}}"/>
</rule>
试试这个
<rule name="LowerCaseRule" stopProcessing="true">
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{URL}" pattern=".*[A-Z].*" ignoreCase="false" />
</conditions>
<action type="Redirect" url="{ToLower:{URL}}" />
</rule>
这对我来说更好。我注意到,{URL}
无法正确解析当您有类似于cassete.axd/scripts/myscript.js?xxx
的路径时,它将重定向到caste.axd?xxx
<rule name="LowerCaseRule - HTTPS">
<match url="[A-Z]" ignoreCase="false"/>
<conditions>
<add input="{HTTPS}" pattern="on" ignoreCase="true"/>
</conditions>
<action type="Redirect" url="https://{ToLower:{HTTP_HOST}}{ToLower:{PATH_INFO}}" appendQueryString="true"/>
</rule>
<rule name="LowerCaseRule - HTTP">
<match url="[A-Z]" ignoreCase="false"/>
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true"/>
</conditions>
<action type="Redirect" url="http://{ToLower:{HTTP_HOST}}{ToLower:{PATH_INFO}}" appendQueryString="true"/>
</rule>
希望这对别人有帮助