0

我必须在我的 IIS 配置中遵循两条规则(根据 scottgu):

<rule name="RemoveTrailingSlashRule1" stopProcessing="true">
    <match url="(.*)/$" />
    <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    </conditions>
    <action type="Redirect" url="{R:1}" />
</rule>

<rule name="CanonicalHostNameRule1" enabled="true">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^dev\.testing\.ch$" negate="true" />
    </conditions>
    <action type="Redirect" url="http://dev.testing.ch/{R:1}" />
</rule>

CanonicalHostNameRule1 将所有http://testing.ch转发到http://www.testing.ch/

第二条规则删除了退格/

如果我可以将空的 testing.ch 请求转发到 www.testing.ch 会更好(没有退格)。但是,如果我像这样删除它显然是行不通的:

<action type="Redirect" url="http://dev.testing.ch{R:1}" />
4

1 回答 1

0

你的规则没有错。没有必要将它们组合起来,因为对http://www.testing.ch/的请求不会被第一条规则捕获。这是因为/域名后的第一个不是与正则表达式匹配的 URL 的一部分。

PS:假设这些规则来自您的开发网站(dev.testing.ch)而不是实际网站。

于 2012-11-16T20:07:24.383 回答