301重定向在IIS 7中不起作用 [英] 301 redirect not working in IIS 7
问题描述
我需要创建此301重定向规则:
/blog/item.asp?n=12817
重定向到 / blog / item / 12817
I need to create this 301 redirect rule:
/blog/item.asp?n=12817
redirect to /blog/item/12817
我在IIS URL Rewrite模块中使用以下参数创建了一条规则:
I created a rule in IIS URL Rewrite module with these parameters :
模式: ^ blog / item.asp \?n =([0-9] +)
重定向网址:博客/项目/ {R:1}
当我在IIS中测试它时,它的工作原理很好,它在我的web.config中创建了这个规则:
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>
但是当我导航到 /blog/item.asp?n= 12817
在浏览器中显示无法找到资源。
错误,文字请求的网址:/blog/item.asp
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?
谢谢
推荐答案
好的,我创建了另一个有效的规则:
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>
仍然想知道为什么Url重写模块会生成不起作用的规则?
Still wondering why would Url rewriting module generates rules which don't work?
这篇关于301重定向在IIS 7中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!