我在我的网络配置文件中有这两条规则来强制https并从网址中删除www。
<rule name="Remove WWW" stopProcessing="true">
<match url="^(.*)$" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(https?://)?www\.(.+)$" />
</conditions>
<action type="Redirect" url="{C:1}{C:2}" redirectType="Permanent" appendQueryString="false"/>
</rule>
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{R:1}" redirectType="Found" appendQueryString="false" />
</rule>
注意:我在SO和几乎所有的博客上都经历了几乎所有的问题,但还没有运气:(。有些SO帖子是;
Proper method to remove www from address using IIS URL Rewrite
URL Rewrite Remove WWW From HTTPS
http://madskristensen.net/post/url-rewrite-and-the-www-subdomain
http://www.serverintellect.com/support/iis/url-rewrite-to-redirect-www-iis7/
http://www.bradymoritz.com/iis7-url-rewrite-remove-www-from-all-urls/
....
答案 0 :(得分:0)
确保将规则放在system.webServer下的web.config中 - &gt;重写 - &gt;规则。
这应该适合你:
<system.webServer>
<rewrite>
<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="Off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
<rule name="Remove WWW" patternSyntax="Wildcard" stopProcessing="true">
<match url="*" />
<conditions>
<add input="{CACHE_URL}" pattern="*://www.*" />
</conditions>
<action type="Redirect" url="{C:1}://{C:2}" redirectType="Permanent" />
</rule>
<rewrite>
</system.webServer>