我们有一个 IIS 8.5 设置,其中一个网站绑定(bind)到 domain.com,并包含许多以 domain.com/app1、domain.com/app2 等访问的 IIS 应用程序。
这些应用程序中的每一个都指向相同的物理路径,因此它们都共享一个 web.config。这是一个特定的 CMS 配置。
我已将常用的 URL 重写规则(重定向到 HTTPS、强制小写、添加尾部斜杠等)应用于每个应用程序共享的 web.config,但我意识到这些规则仅适用于应用程序名称后的 URL。我拥有的规则只是使用 URL 重写 GUI 添加的标准规则:
<rewrite>
<rules>
<rule name="Enforce lowercase" stopProcessing="true">
<match url="[A-Z]" ignoreCase="false" />
<action type="Redirect" url="{ToLower:{URL}}" redirectType="Permanent" />
</rule>
<rule name="Add trailing slash" 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}/" redirectType="Permanent" />
</rule>
<rule name="Redirect to HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
因此,例如,http://domain.com/APP1/PATH
重定向到 https://domain.com/APP1/path/
。此外,https://domain.com/app1
不会重定向到 https://domain.com/app1/
。
HTTPS 规则很好,但谁能告诉我如何配置其他 2 条规则,以便它们与整个 URL 一起工作,请记住特定的应用程序名称(app1、app2 等)需要进行通用处理.
更新
我发现我可以使用 IIS 中的全局规则(在服务器级别)强制使用小写 URL,这足以满足我的需要。但似乎无法复制用于添加/删除尾部斜线的网站级规则。
最佳答案
您只需更改操作 URL。
<rule name="Add trailing slash" 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="https://{HTTP_HOST}{REQUEST_URI}/" redirectType="Permanent" />
</rule>
关于iis - 如何为 IIS 应用程序正确应用 URL 重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39589557/