【问题标题】:301 redirect not working in IIS 7301 重定向在 IIS 7 中不起作用
【发布时间】:2012-01-12 10:09:06
【问题描述】:

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

我使用这些参数在 IIS URL 重写模块中创建了一个规则:

模式:^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>

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

为什么会这样?我需要在其他地方切换吗?

谢谢

【问题讨论】:

    标签: iis redirect iis-7 url-rewriting url-rewrite-module


    【解决方案1】:

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

    <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 重写模块会生成不起作用的规则?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-24
      • 1970-01-01
      • 1970-01-01
      • 2012-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多