301 重定向在 IIS 7 中不起作用

Bur*_*jua 1 iis redirect iis-7 url-rewriting url-rewrite-module

我需要创建这个 301 重定向规则: /blog/item.asp?n=12817redirect to/blog/item/12817

我使用以下参数在 IIS URL Rewrite 模块中创建了一个规则:

图案: ^blog/item.asp\?n=([0-9]+)

重定向网址: blog/item/{R:1}

当我在 IIS 中测试它时它工作正常,它在我的 web.config 中创建了这个规则:

<rule name="Asp classic Legacy 301 redirect" stopProcessing="true">
   <match url="^blog/item.asp\?n=([0-9]+)" />
   <action type="Redirect" url="blog/item/{R:1}" appendQueryString="true" />
</rule>
Run Code Online (Sandbox Code Playgroud)

但是当我/blog/item.asp?n=12817在浏览器中导航时,它仍然显示我的The resource cannot be found.文本错误Requested URL: /blog/item.asp

为什么可以?我需要在其他地方切换其他东西吗?

谢谢

Bur*_*jua 5

好的,我创建了另一个有效的规则:

<rule name="Asp classic legacy 301 redirect">  
  <match url="blog/item\.asp$" />  
    <conditions>  
      <add input="{QUERY_STRING}" pattern="n=(\d+)" />  
    </conditions>  
    <action type="Redirect" url="blog/item/{C:1}" redirectType="Permanent" appendQueryString="false"/>  
</rule> 
Run Code Online (Sandbox Code Playgroud)

仍然想知道为什么 Url 重写模块会生成不起作用的规则?