目前,在我的生产服务器上,我的入站规则设置如下,它可以满足我的所有要求。
入境规则如下。
Match URL section
Requested URL: Matches the Pattern
Using: Regular Expression
Pattern: (.*)
Ignore Case: checked.
Conditions section
Logical grouping: Match All.
Input: {HTTPS}
Type: Matches the Pattern
Pattern: ^OFF$
Track capture groups across conditions: unchecked.
Action section:
Action type: Redirect
Redirect URL: https://www.domainname.com/{R:0}
Append query string: checked.
Redirect Type: Permanent (301).
我的要求是: 当用户输入
时https://beta.domain.com it should redirect to https://www.domain.com.
如果用户输入
http://beta.domain.com it should redirect to https://www.domain.com.
如果用户输入
http://www.domain.com it should redirect to https://www.domain.com
如果用户输入
http://domain.com it should redirect to https://www.domain.com
提前致谢。 任何帮助将不胜感激。
提前致谢。
答案 0 :(得分:3)
这不是具体的条件假设吗?它会检查HTTPS是否为OFF,然后才会发生重定向。如果HTTPS为ON,则不会重定向,否则您将无限重定向。
如果您始终希望主机名为www.domainname.com
,则应将其添加为附加条件。 E.g:
<rule name="Force HTTPS and host name: www.domainname.com" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" negate="true" pattern="^ON$" />
<add input="{HTTP_HOST}" negate="true" pattern="^www\.domainname\.com$" />
</conditions>
<action type="Redirect" url="https://www.domainname.com/{R:0}" appendQueryString="true" redirectType="Permanent" />
</rule>
如果HTTPS
不 ON
或HTTP_HOST
不 www.domainname.com
,则会重定向。只有两者都是真的,它才会重定向。