繁体   English   中英

如何通过web.config从URL中删除查询字符串

[英]How to remove querystring from a url via web.config

我需要所有网址的301重定向,例如

xyz.com/searchitems?key1=val1&key2=val2就像

xyz.com/searchitems

即我想从URL中删除查询字符串。 到目前为止,我已经在我的web.config编写了此内容

        <rewrite>
      <rules>
        <rule name="Rewrite to searchitems">
          <match url="^searchitems?$" />
<conditions>
    <add input="{QUERY_STRING}" pattern="(.*)" />
  </conditions>
          <action type="Redirect" redirectType="Permanent" url="{R:0}" appendQueryString="false"  />
        </rule>
      </rules>
   </rewrite>

但它使重定向循环

编辑:

我只是为这个URL“ xyz.com/searchitems”而不是所有URL删除了querystring。 网址中可以有任意数量的查询字符串参数。

尝试这个:

  <rewrite>
      <rules>
        <rule name="Custom rule" stopProcessing="true">
          <match url="^searchitems" />
          <conditions>
            <add input="{QUERY_STRING}" pattern="(.+)" />
          </conditions>
          <action type="Redirect" url="/searchitems" appendQueryString="false" />
        </rule>
      </rules>
    </rewrite>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM