Cha*_*son 4 regex iis url-rewriting iis-8
希望删除特定的查询字符串参数.文件夹名称可以不同,并且specs参数的长度可以随数字的任何组合而变化.只要有specs参数,无论值如何,都会剥离该参数并重定向到http://example.com/folder
示例输入:
http://example.com/folder1?specs=10,13,14,18,20,29http://example.com/folder2?specs=14,18,20将重定向到(分别):
http://example.com/folder1http://example.com/folder2不要删除任何其他查询字符串参数.即
http://example.com/folder1?page=1不会被重定向.
尽管看起来像使用IIS重写规则测试工具时那样尝试了规则,但没有工作:
<rule name="SpecsSpiderCrawl" stopProcessing="true">
<match url="(\/\/.*\/)(.*)\?" />
<conditions>
<add input="{QUERY_STRING}" pattern="specs=.*" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:2}" appendQueryString="false" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)
我太难了.这有效:
<rule name="SpecsSpiderCrawl" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{QUERY_STRING}" pattern="specs=.*" />
</conditions>
<action type="Redirect" url="http://{HTTP_HOST}/{R:0}" appendQueryString="false" redirectType="Permanent" />
</rule>
Run Code Online (Sandbox Code Playgroud)
{HTTP_HOST} 只是uri的example.com部分{R:0} 将获取文件夹名称appendQueryString="false" 将删除整个查询字符串(这对我的用例很好.