【发布时间】:2018-07-03 14:09:11
【问题描述】:
Web.config URL 重写让我头疼 :-) 我正在尝试按照以下条件设置重写规则:
- 它应该只产生一个重定向
- 忽略资源
- 删除 default.aspx
- 删除尾部斜杠
- 不使用自定义文件扩展名时小写(不是查询字符串)
- 强制 www
- 强制 https
所有这一切都很好,除非原始网址中已经包含 WWW。如果 url 有 WWW,那么它将遵循所有规则,但不会重定向到 HTTPS。
任何帮助将不胜感激!
这是我目前所拥有的 (inspired by this great article):
<rules>
<rule name="WhiteList - resources" stopProcessing="true">
<match url="^resources/" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="None" />
</rule>
<rule name="SEO - remove default.aspx" stopProcessing="false">
<match url="(.*?)/?default\.aspx$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_METHOD}" pattern="GET" />
</conditions>
<action type="Rewrite" url="_{R:1}" />
</rule>
<rule name="SEO - Remove trailing slash" stopProcessing="false">
<match url="(.+)/$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_METHOD}" pattern="GET" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
</conditions>
<action type="Rewrite" url="_{R:1}" />
</rule>
<rule name="SEO - ToLower" stopProcessing="false">
<match url="(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_URI}" pattern="\.pngx|\.jpgx|\.gifx|\.bmpx|\.orcx" negate="true" />
<add input="{HTTP_METHOD}" pattern="GET" />
<add input="{R:1}" pattern="[A-Z]" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="_{ToLower:{R:1}}" />
</rule>
<rule name="ADD WWW IF NOT PRESENT" stopProcessing="true">
<match url="^(_*)(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^www\.testssl\.orca-bree\.be$" negate="true" />
<add input="{HTTP_METHOD}" pattern="GET" />
</conditions>
<action type="Redirect" url="https://www.testssl.orca-bree.be/{R:2}" redirectType="Permanent" />
</rule>
<rule name="redirect" stopProcessing="true">
<match url="^(_+)(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_METHOD}" pattern="GET" />
</conditions>
<action type="Redirect" url="{R:2}" redirectType="Permanent" />
</rule>
</rules>
【问题讨论】:
标签: ssl url-rewriting web-config