0

在我的 Windows 2012 服务器上,我在 IIS 中安装了 URL 重写模块。我已按照本指南将非 www 重定向到 web.config 中的 www:http: //www.surfingsuccess.com/asp/iis-url-rewrite.html#.VF6GBid0yAU

到目前为止,一切都很好!

唯一的问题是我们还托管子域“api.example.com”。当我在 web.config 中应用代码时,此 API 停止工作。

我的问题是:下面的代码有什么问题?为什么当我尝试将非 www 重定向到 www(“api.example.com”除外)时子域停止工作?

    <rewrite>
        <rules>
            <rule name="CanonicalHostNameRule1">
                <match url="(.*)" />
                <conditions>
                    <add input="{HTTP_HOST}" pattern="^www\.example\.com$" negate="true" />
                    <add input="{HTTP_HOST}" pattern="^api\.example\.com$" negate="true" />
                </conditions>
                <action type="Redirect" url="http://www.example.com/{R:1}" />
            </rule>
        </rules>
    </rewrite>
4

2 回答 2

0

我有类似的检查,我有相同的规则,但指定的模式不同。

我的建议是启用失败的请求跟踪来检查 URL 重写。 http://www.iis.net/learn/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules

编辑:更新规则。

 <rewrite>
            <rules>
                <rule name="non-root" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{HTTP_HOST}" pattern="^(www.example.com)$" negate="true" />
                        <add input="{HTTP_HOST}" pattern="^(api.example.com)$" negate="true" />
                        <add input="{HTTP_HOST}" pattern="^(example.com)$" />
                    </conditions>
                    <action type="Redirect" url="http://www.example.com/{R:1}" />
                </rule>
            </rules>
        </rewrite>
于 2014-11-12T16:23:28.437 回答
0

实际上,我的重写代码没有任何问题。API 停止工作的原因是因为它引用了站点的顶级域(example.com),这导致与重写代码发生冲突。在更改对域的 www 版本(www.example.com)的引用后,一切正常。

于 2014-11-21T10:12:34.423 回答