簡體   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