3

我从来没有做过 URL 重写(重定向)。我有一个网站http://sub.sub.domain.ext/app/。“app”表示“应用程序”,而不是虚拟目录。当用户导航到http://sub.sub.domain.ext/app(无斜杠)时,我需要 IIS 7 将他重定向到带有斜杠的 URL。

问题是我希望在用户导航到应用程序时应用规则。我不希望将斜杠附加到每个文件名。

我曾尝试修改 IIS7 管理器中的预定义规则,但没有成功。我尝试过精确匹配整个 URL,限制条件,或者只是使用原始的预定义规则。但即使使用原始规则,它也会重写所有后续请求文件/dirs/URL,但不会将用户从http://sub.sub.domain.ext/app重定向到http://sub.sub.domain .ext/app/

4

1 回答 1

3

您正在寻找的规则可能很简单:

<rule name="Add trailing slash" stopProcessing="true">
    <match url="^app$" negate="false" />
    <action type="Redirect" url="{R:0}/" />
</rule>

url="^app$"模式仅匹配 url http://www.yourwebsite.com/app,不匹配其他内容。
如果您需要将此行为限制为 host sub.sub.domain.ext,您可以添加一个条件:

<rule name="test" stopProcessing="true">
    <match url="^app$" negate="false" />
    <action type="Redirect" url="{R:0}/" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^sub.sub.domain.ext$" />
    </conditions>
</rule>
于 2013-02-14T15:41:18.900 回答