iis重写将所有页面重定向到主页

时间:2017-10-30 11:40:51

标签: regex redirect iis url-rewriting

我正在尝试将IIS站点上的所有页面重定向到主页/ root。我的规则似乎有效,但是我得到了“localhost重定向你太多次”的错误。

规则需要在斜杠之前排除任何内容,例如mysite.com/mypage /

<rule name="redirect_all_bar_home_root" stopProcessing="true">
          <match url="^(.*)$" />
            <conditions>
              <add input="{REQUEST_URI}" pattern="^$" negate="true"/>
            </conditions>
          <action type="Redirect" url="http://localhost" />
        </rule>

2 个答案:

答案 0 :(得分:1)

这条规则可以做到:

<rule name="redirect_all_bar_home_root" stopProcessing="true">
    <match url="^$" negate="true"/>
     <action type="Redirect" url="/" />
</rule>

正则表达式:^$在字符串为空时匹配(它是主页)

negate="true"否定正则表达式。 All URLs which are not homepage

答案 1 :(得分:0)

我只是有一个要求。以下规则将满足您的需要,但它不会尝试重定向文件url,因此图像仍可在您的主页上工作

<rule name="RedirectAllToRoot stopProcessing="true">
    <match url="^$" negate="true" />
    <action type="Redirect" url="/" redirectType="Temporary" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    </conditions>
</rule>
相关问题