Asp.net 小写URL的IIS重写规则';s

Asp.net 小写URL的IIS重写规则';s,asp.net,iis,url-rewriting,Asp.net,Iis,Url Rewriting,我有一个IIS重写规则将所有URL转换为小写 <rewrite> <rules> <rule name="LowerCaseRule1" stopProcessing="true"> <match url="[A-Z]" ignoreCase="false" /> <action type="Redirect" url="{ToLower:{URL}}" />

我有一个IIS重写规则将所有URL转换为小写

<rewrite>
    <rules>
        <rule name="LowerCaseRule1" stopProcessing="true">
            <match url="[A-Z]" ignoreCase="false" />
            <action type="Redirect" url="{ToLower:{URL}}" />
        </rule>
    </rules>
</rewrite>
如何修改上述规则,使其也包含查询字符串?

根据我的评论(引用问题),我可以想象该规则如下所示:

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


免责声明,我在Windows XP上工作,所以我只有IIS 6.0,所以我无法检查语法是否正确!可能需要一些调整…

我无法制定一个规则来捕获
{URL}
{QUERY\u STRING}
并以我希望的方式显示URL。所以,我把它分成两条规则

将URL改为小写

<rule name="UrlToLowercase" stopProcessing="true">
  <match url=".*[A-Z].*" ignoreCase="false" />
    <conditions>                          
      <add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" />
      <add input="{URL}" pattern="^.*\.(axd|css|js|jpg|jpeg|png|gif|txt|xml|svg|pdf)$" negate="true" ignoreCase="true" /> 
    </conditions>
    <action type="Redirect" redirectType="Permanent" url="{ToLower:{URL}}" />
</rule> 

查询字符串为小写的URL

<rule name="UrlWithQueryStringToLowercase" stopProcessing="true">
  <match url="(.*)" ignoreCase="false" />
    <conditions trackAllCaptures="true">   
      <add input="{QUERY_STRING}" pattern="(.*)" /> 
      <add input="{QUERY_STRING}" pattern=".*[A-Z].*" ignoreCase="false" />
      <add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" />
    </conditions>
    <action type="Redirect" redirectType="Permanent" url="{ToLower:{URL}}?{ToLower:{C:0}}" appendQueryString="false" />
</rule>

这应该涵盖每个案例,如果没有,请让我知道。:)

我增加了一些额外的条件,你可能想离开或带走

忽略以axd、css、js、jpg等结尾的路径。如果没有此规则,您将无法从服务器加载大写字母的文件


将使用POST方法忽略请求。如果没有此规则,指定大写URL的帖子将因为301而丢失数据(GET没有此问题)。

尽管这可能不是问题,但您是否应该小心?你百分之百确定这个案子在你的提问中永远都不重要吗?经过一点搜索,这可能会帮你解决问题吗?@Bartdude important?你能详细说明一下吗?@Damon是的,我想这就是我需要的。但我不想做太多的改变。只是对我已有的配置进行了更改。您能帮忙吗?@user1089173>好吧,让我们假设您通过querystring传递搜索词,区分“MySearchTerm”和“MySearchTerm”可能很重要,在这种情况下,您不希望重写参数。换句话说:在IIS上,URL大小写并不重要,但querystring大小写可能很重要。现在我不知道你的情况/网站,也许这只是一个无用的评论,但可能是你忽略了一些东西。
<rule name="UrlWithQueryStringToLowercase" stopProcessing="true">
  <match url="(.*)" ignoreCase="false" />
    <conditions trackAllCaptures="true">   
      <add input="{QUERY_STRING}" pattern="(.*)" /> 
      <add input="{QUERY_STRING}" pattern=".*[A-Z].*" ignoreCase="false" />
      <add input="{REQUEST_METHOD}" matchType="Pattern" pattern="POST" ignoreCase="true" negate="true" />
    </conditions>
    <action type="Redirect" redirectType="Permanent" url="{ToLower:{URL}}?{ToLower:{C:0}}" appendQueryString="false" />
</rule>