首页 > 解决方案 > URL重写导致重定向你太多次

问题描述

我正在使用 IIS url 重写规则从 IP 地址重定向到具有以下规则的域名。

<rule name="IPHit" enabled="true" stopProcessing="false">
    <match url="(.*)" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="10.32.1.132" />
    </conditions>
    <action type="Redirect" url="https://daart-qa.sandbox.aimsplatform.com/eds-daas/{R:1}" redirectType="Permanent" appendQueryString="true" />
</rule>

不幸的是,当我转到https://daart-qa.sandbox.aimsplatform.com/eds-daas时,这会导致无限循环重定向。

如何在没有 dns 条目的无限循环的情况下从 IP 地址重定向?

标签: iisurl-rewriting

解决方案


Your rule will redirect 10.32.1.132/eds-daas to https://daart-qa.sandbox.aimsplatform.com/eds-daas/eds-daas. Is that expected behavior?

May I know your only face this infinite loop when you access specific URL or all requests hitted by IP address. What loop URL did you see in web browser developer tool? Post the symtptom of loop URL would help us find the root cause.

enter image description here

Or you need to redirect request 10.32.1.132/eds-daas to https://daart-qa.sandbox.aimsplatform.com/eds-daas? If so you may need two rules side by side.

  <rule name="IPHit" enabled="true" stopProcessing="true">
    <match url="(.*)" />
    <conditions>
                        <add input="{HTTP_HOST}" pattern="10.32.1.132" />
                        <add input="{REQUEST_URI}" pattern="^/eds-daas(.*)" negate="true" />
    </conditions>
    <action type="Redirect" url="https://daart-qa.sandbox.aimsplatform.com/eds-daas/{R:1}" redirectType="Permanent" appendQueryString="true" />
</rule>

                <rule name="IP-HIT2" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="10.32.1.132" />
                        <add input="{REQUEST_URI}" pattern="^/eds-daas(.*)" />
                    </conditions>
                    <action type="Redirect" url="https://daart-qa.sandbox.aimsplatform.com/eds-daas{C:1}" />
                </rule>

推荐阅读