【发布时间】:2015-07-27 13:29:04
【问题描述】:
我想在一个请求中执行多个301 重定向,我发现this article 很有帮助。但是,我有一个问题,http://example.com 重定向到 https://www.example.com 但 https://example.com 不重定向到 https://www.example.com
下面是我的例子:
- SEO - 删除 default.aspx(工作正常,但没有 HTTPS)
https://www.example.com/app/default.aspx => https://www.example.com/app/
但是http://www.example.com/app/default.aspx => http://www.example.com/app/
SEO - 删除尾部斜杠(不起作用且没有 HTTPS,如上所述)
所有链接都改为斜杠
http://www.example.com/app => http://www.example.com/app/
https://www.example.com/app => https://www.example.com/app/SEO - ToLower(工作正常,但没有上述 HTTPS)
http://www.example.com/APP => http://www.example.com/app
https://www.example.com/APP => https://www.example.com/appSEO - http 规范重定向(100% 有效)
http://example.com/app => https://www.example.com/app-
SEO - https 规范重定向(根本不起作用)
https://example.com/app => https://www.example.com/app - 失败 SEO - 非规范重定向(不能 100% 工作。如果没有此规则,样式表将无法加载,但与上述任何不匹配的其他链接也不会出现)
@ 987654338@ => https://example.com/app/
http://example.com/app => http://example/com/app/
https://www.example.com/app => https://www.example.com/app/
http://www.example.com/app => http://www.example.com/app/
这是我实现的,问题如上。
<rewrite>
<rules>
<clear />
<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="{HTTP_METHOD}" pattern="GET" />
<add input="{R:1}" pattern="[A-Z]" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="_{ToLower:{R:1}}" />
</rule>
<rule name="SEO - http canonical redirect" stopProcessing="true">
<match url="^(_*)(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" matchType="Pattern" pattern="^www\.example\.com$" ignoreCase="true" negate="true" />
<add input="{HTTP_METHOD}" pattern="GET" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:2}" />
</rule>
<rule name="SEO - https canonical redirect" stopProcessing="true">
<match url="^(_*)(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" matchType="Pattern" pattern="^www\.example\.com$" ignoreCase="true" negate="true" />
<add input="{HTTP_METHOD}" pattern="GET" />
<add input="{HTTPS}" pattern="^ON$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:2}" />
</rule>
<rule name="SEO - non-canonical redirect" stopProcessing="true">
<match url="^(_+)(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_METHOD}" pattern="GET" />
</conditions>
<action type="Redirect" url="{R:2}" />
</rule>
</rules>
</rewrite>
【问题讨论】:
-
考虑在 https 条件后添加 ignoreCase="true":
-
不幸的是托尼没有帮助。我今天早上试过了。
标签: redirect iis-7 web-config rewrite isapi-rewrite