IIS重写重定向不起作用

时间:2014-08-12 10:23:07

标签: iis

好的我觉得这很简单,我有很多URL http://www.domain.com/Home/Features

http://www.domain.com/Home/Costs

http://www.domain.com/Premier

我要重定向到另一个页面(即www.domain.com): 如

<rewrite>
  <rules>
    <rule name="Redirect" stopProcessing="true">
      <match url="^url1$" />
      <conditions>
        <add input="{HTTP_HOST}" pattern="http://www.domain.com/Home/Features" />
      </conditions>
      <action type="Redirect" url="http://www.domain.com" appendQueryString="false" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

我一直得到404,我做错了什么?

2 个答案:

答案 0 :(得分:0)

由于这是一个目录,您需要两个规则,而且您确实不需要HTTP_HOST的附加条件。如果由于某种原因确实需要将模式设置为pattern="^domain.com$"(https,子域等)

一条规则:

http://www.domain.com/Home/Features

和其他

http://www.domain.com/Home/Features/

所以这就是:

<rewrite>
  <rules>
    <rule name="RedirectRule1" stopProcessing="true" >
      <match url="Home/Features/(.*)" />
      <action type="Redirect" url="http://www.domain.com" appendQueryString="false" redirectType="Permanent" />
    </rule>    
    <rule name="RedirectRule2" stopProcessing="true" >
      <match url="Home/Features(.*)" />
      <action type="Redirect" url="http://www.domain.com" appendQueryString="false" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

答案 1 :(得分:0)

这有效

<rule name="Features" stopProcessing="true">
  <match url="Home/Features" />
  <action type="Redirect" url="http://www.domain.com" redirectType="Permanent" />
</rule>