0

私の Windows 2012 サーバーでは、IIS に URL Rewrite モジュールをインストールしました。このガイドに従って、web.config で非 www を www にリダイレクトしました: http://www.surfingsuccess.com/asp/iis-url-rewrite.html#.VF6GBid0yAU

ここまでは順調ですね!

唯一の問題は、サブドメイン「api.example.com」もホストしていることです。web.config でコードを適用すると、この API が機能しなくなります。

私の質問は次のとおりです。以下のコードの何が問題になっていますか? 「api.example.com」以外の非 www を www にリダイレクトしようとすると、サブドメインが機能しなくなるのはなぜですか?

    <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 に答える