【发布时间】:2015-12-31 05:16:42
【问题描述】:
我的 IIS 网站目前以 http://mywebsite.com 访问,我有 3 个与 url 重写相关的目标:
- 重定向到网站的新名称 mynewwebsite.com
- 如果存在 www 前缀,则删除它(例如 www.mywebsite.com -> mywebsite.com 或 www.mynewwebsite.com --> mynewwebsite.com
- 重定向到 SSL
总之,我想将所有入站请求重定向到https://mynewwebsite.com/anything*。
必须考虑的输入案例是
- http://mynewwebsite.com/随便*
- http://www.mynewwebsite.com/随便*
- http://mywebsite.com/任何东西*
- http://www.mywebsite.com/随便*
- https://mywebsite.com/随便*
- https://www.mywebsite.com/随便*
- https://www.mynewwebsite.com/任何东西*
我的重写规则如下:
<rewrite>
<rules>
<rule name="Do stuff" enabled="true">
<match url="(.*)" ignoreCase="false" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTPS}" pattern="off" />
<add input="{HTTP_HOST}" pattern="mywebsite.com" />
<add input="{HTTPS}" pattern="^www.mynewwebsite\.com$" />
</conditions>
<action type="Redirect" url="https://mynewwebsite.com/{R:1}" appendQueryString="true" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
设置此规则后,以下输入案例将失败(www 未被剥离):https://www.mynewwebsite.com/anything*
我已经充分反对这一点,以至于我质疑我对规则定义如何工作的基本理解。
- 任何东西可能存在或根本不存在
【问题讨论】:
标签: iis url-rewriting url-redirection http-redirect