【问题标题】:Add HTTPS redirect to existing rule to rewrite subdomain to a folder将 HTTPS 重定向添加到现有规则以将子域重写到文件夹
【发布时间】:2016-07-19 00:58:25
【问题描述】:

我一直在使用以下模式为我的主站点和子域设置目录结构:

A.每个站点都在自己的子文件夹中,包括主站点,所以我有类似的东西

\wwwroot
     \main
     \subdomain1

B. wwwroot 中只有 1 个文件。具有以下内容的 web.config 文件

<configuration>
<system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <rewrite>
        <rules>
            <rule name="Rewrite to folder1" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^www.MyMainDomain.com$" />
                </conditions>
                <action type="Rewrite" url="main/{R:1}" />
            </rule>
            <rule name="subdomain1.MyMainDomain.com to sub folder" enabled="true" stopProcessing="true">
                <match url="(.*)" ignoreCase="true" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{HTTP_HOST}" pattern="^subdomain1\.MyMainDomain\.com$" ignoreCase="false" />
                    <add input="{PATH_INFO}" pattern="^/subdomain1($|/)" negate="true" />
                </conditions>
                <action type="Rewrite" url="\subdomain1\{R:0}" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

如何将 https 重定向仅添加到子域?

调试正在重写/重定向的内容的最佳方法是什么?

【问题讨论】:

  • 你让它工作了吗?我有同样的问题,不知道如何处理。唯一的区别是我没有“主”,但只需要将 example.com/subdomain1 重定向到 subdomain1.example.com/subdomain1

标签: url-rewrite-module


【解决方案1】:

我不确定调试重写/重定向流量的最佳方法。

根据您的情况,您应该检查它是否是 http 请求:

<add input="{HTTP}" negate="true" pattern="^ON$" />

或检查是否缺少 https 请求:

<add input="{HTTPS}" negate="true" pattern="^OFF$" />

另外,尝试将 type="rewrite" 的行从重写更改为永久重定向,这样浏览器就会获得正确的 301 响应代码。

<action type="Redirect" url="https://{HTTP_HOST}/" redirectType="Permanent" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 2013-06-02
    • 2015-09-01
    • 2016-07-30
    • 2013-04-01
    相关资源
    最近更新 更多