【问题标题】:Web.config redirect one domain to non-https folder and another domain to https folderWeb.config 将一个域重定向到非 https 文件夹,将另一个域重定向到 https 文件夹
【发布时间】:2013-04-01 10:25:41
【问题描述】:

我的网站有一个域别名。我想知道如何将 domainA.ext 的请求重定向到 https://domainA.ext/folderA 并将 domainB.ext 的请求重定向到 http://domainB.ext/folderB

目前我有以下规则将所有 http 请求重定向到 https,但它将所有请求重定向到 https:

<rule name="Redirect to https" stopProcessing="true">
                    <match url="(.mydomain.ext*)" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                    </conditions>
                    <action type="Redirect" url="https://mydomain.ext}" redirectType="Permanent" />*
                </rule>

它是 Windows server 2008,但我的 cms 是 PHP 的。

【问题讨论】:

  • 你能定义所有的案例和预期的结果吗?例如,如果有人点击http://domainB.ext 怎么办?他们必须被重定向到http://domainB.ext/folderB 还是留在http://domainB.ext
  • http://domainB.ext/folderB 可以。

标签: url-rewriting web-config rewrite


【解决方案1】:

我想不出比 4 条不同的规则更简单的事情了。

domainA.ext 的前两个:

<rule name="Check path folderA" stopProcessing="true">
    <match url="^folderA" negate="true" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="domainA\.ext$" />
    </conditions>
    <action type="Redirect" url="https://domainA.ext/folderA/" />
</rule>
<rule name="Check SSL for domainA" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="domainA\.ext$" />
        <add input="{HTTPS}" pattern="^OFF$" />
    </conditions>                         
    <action type="Redirect" url="https://domainA.ext/folderA/" />
</rule>
  • 第一条规则:如果路径不以folderA开头,则重定向到https://domainA.ext/folderA/
  • 第二条规则:如果HTTPS关闭,它会重定向到https://domainA.ext/folderA/

还有domainB.ext 的下两个:

<rule name="Check path folderB" stopProcessing="true">
    <match url="^folderB" negate="true" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="domainB\.ext$" />
    </conditions>
    <action type="Redirect" url="http://domainB.ext/folderB/" />
</rule>
<rule name="Check no SSL for domainB" stopProcessing="true">
    <match url="(.*)" />
    <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_HOST}" pattern="domainB\.ext$" />
        <add input="{HTTPS}" pattern="^ON$" />
    </conditions>                         
    <action type="Redirect" url="http://domainB.ext/folderB/" />
</rule>
  • 第一条规则:如果路径不以folderB开头,则重定向到http://domainB.ext/folderB/
  • 第二条规则:如果HTTPS开启,它会重定向到http://domainB.ext/folderB/

【讨论】:

    猜你喜欢
    • 2016-01-03
    • 2012-08-13
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多