有条件的 HTTP 重定向 IIS 7
Conditoinal HTTP redirect IIS 7
目前我正在将我所有的 http 请求重定向到 HTTPS 但现在我想添加一个条件,如果 URL 包含 'admin' 然后将 HTTP 请求重定向到 HTTPS,我如何将规则更改为实现这个(例如http://www.example.com/admin/index.html)?
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>
将 url 模式更改为:
<match url=".*admin/.*" />
这似乎与您在 IIS 模式匹配工具中的示例数据相匹配。
匹配其他部分,例如profile 您可以更改正则表达式:
<match url=".*(admin|profile)/.*" />
如果它总是以 admin
或 profile
开头,那么您可以将正则表达式收紧到 ^(admin|profile)/.*
(^
表示模式开始,请参阅 Defining a Pattern on this screen).
目前我正在将我所有的 http 请求重定向到 HTTPS 但现在我想添加一个条件,如果 URL 包含 'admin' 然后将 HTTP 请求重定向到 HTTPS,我如何将规则更改为实现这个(例如http://www.example.com/admin/index.html)?
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
</rule>
将 url 模式更改为:
<match url=".*admin/.*" />
这似乎与您在 IIS 模式匹配工具中的示例数据相匹配。
匹配其他部分,例如profile 您可以更改正则表达式:
<match url=".*(admin|profile)/.*" />
如果它总是以 admin
或 profile
开头,那么您可以将正则表达式收紧到 ^(admin|profile)/.*
(^
表示模式开始,请参阅 Defining a Pattern on this screen).