301 redirect not working in IIS 7

一世执手 提交于 2019-12-02 17:54:08

问题


I need to create this 301 redirect rule: /blog/item.asp?n=12817 redirect to /blog/item/12817

I created a rule in IIS URL Rewrite module with these parameters :

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

redirect url: blog/item/{R:1}

When I test it in IIS it works fine and it created this rule in my 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>

But still when I navigate to /blog/item.asp?n=12817 in browser it shows me The resource cannot be found. error with text Requested URL: /blog/item.asp

Why can it be? Do I need to switch something else somewhere?

Thanks


回答1:


Ok, I created another rule which works:

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

Still wondering why would Url rewriting module generates rules which don't work?



来源:https://stackoverflow.com/questions/8833259/301-redirect-not-working-in-iis-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!