我需要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>
但它正在制作重定向循环
编辑:
我只为此网址“xyz.com/searchitems”删除了查询字符串,而不是所有网址。网址中可以有任意数量的查询字符串参数。
答案 0 :(得分:2)
试试这个:
<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>