【问题标题】:Combination of IIS rewrite rules - redirect to changed domain name, remove hostname prefix redirect to sslIIS重写规则的组合——重定向到改变的域名,去掉主机名前缀重定向到ssl
【发布时间】:2015-12-31 05:16:42
【问题描述】:

我的 IIS 网站目前以 http://mywebsite.com 访问,我有 3 个与 url 重写相关的目标:

  1. 重定向到网站的新名称 mynewwebsite.com
  2. 如果存在 www 前缀,则删除它(例如 www.mywebsite.com -> mywebsite.com 或 www.mynewwebsite.com --> mynewwebsite.com
  3. 重定向到 SSL

总之,我想将所有入站请求重定向到https://mynewwebsite.com/anything*。

必须考虑的输入案例是

我的重写规则如下:

<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


    【解决方案1】:

    我得出了以下有效的规则,但恐怕这是巧合,而不是我真正了解正在发生的事情。欢迎评论。

    <rewrite>
      <rules>
        <rule name =" Force HTTPS" enabled="true">
          <match url =" (.*)" ignoreCase= "false " />
          <conditions logicalGrouping =" MatchAny" >
            <add input =" {HTTP_HOST}" negate="true" pattern =" ^mynewwebsite\.com$" />
            <add input =" {HTTPS}" pattern= "^www.mynewwebsite\.com$ " />
            </conditions>
          <action type =" Redirect" url= "https://mynewwebsite.fm/{R:1} " appendQueryString="true" redirectType =" Permanent" />
        </rule>
      </rules>
    </rewrite>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-28
      • 2013-05-11
      • 1970-01-01
      • 2016-09-20
      • 1970-01-01
      • 2016-08-30
      • 1970-01-01
      • 2018-05-02
      相关资源
      最近更新 更多