【问题标题】:Website subdomain redirect in IISIIS 中的网站子域重定向
【发布时间】:2014-12-26 09:15:56
【问题描述】:

我的IIS 7.5 中有 2 个虚拟目录。这些需要像访问子域一样访问。

例如。

我的域名:mydomain.com

目录1:dir1.mydomain1.com

目录 2:dir2.mydomain1.com

当用户尝试使用http 时,我还需要强制使用https 方案。我在第一个应用程序的web.config 文件中添加了规则:

<rewrite>
    <rules>
        <rule name="Force HTTPS" enabled="true">
            <match url="(.*)" ignoreCase="false" />
            <conditions>
                <add input="{HTTPS}" pattern="off" />
            </conditions>
            <action type="Redirect" url="https://{HTTP_HOST}/" appendQueryString="true" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>

当所需的 URL 为 http://mydomain1.com/dir1 时,它可以工作。 URL 更改为https://mydomain1.com/dir1 请帮助我处理子域规则。

【问题讨论】:

  • 您是否尝试在 IIS 中为 Https 添加新绑定?

标签: asp.net asp.net-mvc http iis url-rewriting


【解决方案1】:

此规则适用于从子域重定向。但是,“www”将被视为子域,因此您可能应该在子域重定向之前处理该子域。

<rule name="Redirect www to nonwww" patternSyntax="Wildcard" stopProcessing="true">
    <match url="*" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{HTTP_HOST}" pattern="www.mydomain.com" />
        </conditions>
        <action type="Redirect" url="https://mydomain.com/{R:0}" />
</rule>

<rule name="RedirectSubdomain" stopProcessing="true">
<match url="(.*)" />
    <conditions trackAllCaptures="true">
        <add input="{HTTP_HOST}" pattern="(.*).mydomain.com" />
    </conditions>
    <action type="Redirect" url="https://mydomain.com/{C:1}" />
</rule>

在这 2 条规则之后,您的强制 https 规则可以放在最后。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-10
    • 2021-09-27
    • 1970-01-01
    • 2015-10-04
    • 1970-01-01
    • 2013-09-24
    相关资源
    最近更新 更多