IIS URL重写失败

时间:2013-11-25 10:45:18

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

我正在尝试实现简单的IIS URL重写。我想将网址重写: about.test.local 改为 text.local / about.html

在下面的配置中,我添加了规则,但它似乎不起作用。有什么问题?

    <rewrite>
        <rules>
            <rule name="Rewrite1" patternSyntax="ExactMatch" stopProcessing="true">
                <match url="about.test.local" />
                <action type="Rewrite" url="http://test.local/about.html" />
            </rule>
            <rule name="Rewrite2" patternSyntax="ExactMatch" stopProcessing="true">
                <match url="http://about.test.local/" />
                <action type="Rewrite" url="http://test.local/about.html" logRewrittenUrl="true" />
            </rule>
        </rules>
    </rewrite>

正如@beavel所提到的,我添加了以下规则,但URL仍然没有被重写:

            <rule name="Rewrite2a" patternSyntax="ExactMatch" stopProcessing="true">
                <match url="(.+)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="about.test.local" />
                </conditions>
                <action type="Rewrite" url="http://test.local/about.html" />
            </rule>
            <rule name="Rewrite2b" patternSyntax="ExactMatch" stopProcessing="true">
                <match url="(.+)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="http://about.test.local/" />
                </conditions>
                <action type="Rewrite" url="http://test.local/about.html" />
            </rule>

1 个答案:

答案 0 :(得分:0)

问题是匹配网址不包含主题,如here所述。如果您有多个主机名绑定到一个IIS站点,并且只想重写一个主机名,您可以执行以下操作:

<rule name="Rewrite1" patternSyntax="ExactMatch" stopProcessing="true">
    <match url="(.+)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="about.test.local" />
    </conditions>
    <action type="Rewrite" url="http://test.local/about.html" />
</rule>