首页 > 解决方案 > 使用 IIS 重写的自定义域和资产重定向

问题描述

我正在尝试进行自定义域映射,其中我必须映射作为自定义域的 custom.seconddomain.com,并且我的应用程序托管在 app.firstdomain.com 上。

所以我为 seconddomain.com 添加了一个 CNAME 条目到域提供商。然后在我的托管 app.firstdomain.com 的服务器中为 custom.seconddomain.com 添加了一个 IIS 条目。我在此 IIS 条目中添加了一个重写规则,以便将应用程序路由重写到 app.firstdomain.com。到目前为止,一切都很好。

<rule name="Subdomain rewrite" stopProcessing="true">
    <match url=".*" />
        <conditions>
            <add input="{HTTP_HOST}" pattern="^((http)?(s)?:\/\/)?custom.seconddomain.com\/(.*)" />
        </conditions>
        <action type="Rewrite" url="http://app.firstdomain.com/" appendQueryString="true" />
</rule>

但现在由于资产和资源仅在 app.firstdomain.com 上可用,因此无法在 custom.seconddomain.com 上加载这些资产。因此,为此我在 IIS 重写规则上添加了一条规则,以将资产请求从 custom.seconddomain.com 重定向到 app.firstdomain.com,但不确定是由于规则的优先级还是其他原因。两条规则似乎不能一起运作。

<rule name="Rule 1">
    <match url="^((http)?(s)?:\/\/)?custom.seconddomain.com\/assets\/(.*)" />
        <conditions>
            <add input="{HTTP_REFERER}" pattern="^$" negate="true" />
        </conditions>
        <action type="Rewrite" url="https://app.firstdomain.com/assets/{R:4}" />
</rule>

我是 IIS 新手,所以我也试图通过图像热链接来实现这一点,以尝试实现预期的结果。你能告诉我我在这里错过了什么或做错了吗?

标签: redirectiisurl-rewritingcustom-domain

解决方案


推荐阅读