【问题标题】:Redirect IIS Request from non-www to www (with multiple domains spanning across multiple TLDs)将 IIS 请求从非 www 重定向到 www(多个域跨越多个 TLD)
【发布时间】:2016-06-03 05:17:50
【问题描述】:

我有一个在 Azure (IIS) 上运行的 ASP.NET MVC 站点。

我想在 web.config 中创建一个重写规则(除非有人有更好的主意),以便将对没有子域的域的任何请求重定向到包含 www 的相同地址。这必须跨多个域、子域和 TLD 工作。

例如:

domain1.com                 -> www.domain.com
domain5.buzz                -> www.domain5.buzz
http://domain2.com          -> http://www.domain2.com
http://domain2.co.uk        -> http://www.domain2.co.uk
sudomain.domain5.buzz       -> sudomain.domain5.buzz
https://domain5.buzz        -> https://www.domain5.buzz

等等……

【问题讨论】:

    标签: redirect iis


    【解决方案1】:

    我能想出解决此问题的唯一方法是静态键入接受的 TLD:

    <rewrite>
        <rules>
            <rule name="RedirectRoot">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAny">
                    <add input="{HTTP_HOST}" pattern="^([a-z0-9]+(-[a-z0-9]+)*)+(\.)(com|net|org|buzz|edu|gov|co.uk)(:[0-9]+)?$"/>
                </conditions>
                <action type="Redirect" url="http://www.{HTTP_HOST}/{R:1}" redirectType="Permanent" />
            </rule>
        </rules>
    </rewrite>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-02
      • 1970-01-01
      • 2015-04-20
      • 2021-04-23
      • 2012-04-29
      • 2010-11-27
      • 2020-12-31
      • 2017-11-03
      相关资源
      最近更新 更多