IIS 7 重定向到新域

发布于 2025-01-11 04:23:01 字数 598 浏览 0 评论 0原文

早上好,

我正在尝试在 IIS 中创建重写规则以将特定页面重定向到新的 url,但是当我应用该规则时没有发生重定向,我错过了什么?代码:

</rule>
                <rule name="Redirect" enabled="false" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{URL}" pattern="^(/)?$" />
                        <add input="{HTTP_HOST}" pattern="domain1/server/sdk/" />
                    </conditions>
                    <action type="Redirect" url="https://domain2/rest/" />
                </rule>

Good morning,

I am trying to create a Rewrite rule in IIS to redirect a specific page to a new url however when I apply the rule no redirect happens what am I missing? Code:

</rule>
                <rule name="Redirect" enabled="false" stopProcessing="true">
                    <match url="(.*)" />
                    <conditions>
                        <add input="{URL}" pattern="^(/)?
quot; />
                        <add input="{HTTP_HOST}" pattern="domain1/server/sdk/" />
                    </conditions>
                    <action type="Redirect" url="https://domain2/rest/" />
                </rule>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里°也失望 2025-01-18 04:23:01

尝试将 REQUEST_URI 添加到模式匹配

<add input="{HTTP_HOST}{REQUEST_URI}" pattern="domain1/server/sdk/" />

匹配网址也可能效果更好,

<match url="^(.*)$" />

同时确保规则已启用,您的版本上有 enabled="false"

这是我的完整规则

<rule name="domain1/server/sdk/" stopProcessing="true">
    <match url="^(.*)$" />
    <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="domain1/server/sdk/" />
    </conditions>
    <action type="Redirect" url="https://domain2/rest/" redirectType="Permanent" appendQueryString="false" />
</rule>

Try adding REQUEST_URI to the pattern match

<add input="{HTTP_HOST}{REQUEST_URI}" pattern="domain1/server/sdk/" />

match url may also work better as

<match url="^(.*)
quot; />

also make sure the rule is enabled, your version has enabled="false" on it

Here is my full rule

<rule name="domain1/server/sdk/" stopProcessing="true">
    <match url="^(.*)
quot; />
    <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="domain1/server/sdk/" />
    </conditions>
    <action type="Redirect" url="https://domain2/rest/" redirectType="Permanent" appendQueryString="false" />
</rule>
朮生 2025-01-18 04:23:01

非常好,非常感谢迈克,我在测试后确实禁用了我的规则,但它不起作用,这就是为什么它显示启用= false,但是我根据你的建议修改了规则,这对我有用!如果这对将来的其他人有帮助,我的完整规则是:

<rules>
                <remove name="Portal Redirect" />
                   <rule name="(rule name)" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="^(.*)$" ignoreCase="false" />
                    <action type="Redirect" url="Domain2/rest/" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="domain1/server/sdk/rest/" />
                    </conditions>
                </rule>

Excellent thank you very much Mike, I did disable my rule after testing it and it did not work which is why it shows enabled=false however I revised the rule per your advice and that worked for me! Incase this is helpful for anyone else in the future my full rule is:

<rules>
                <remove name="Portal Redirect" />
                   <rule name="(rule name)" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="^(.*)
quot; ignoreCase="false" />
                    <action type="Redirect" url="Domain2/rest/" />
                    <conditions logicalGrouping="MatchAny">
                        <add input="{HTTP_HOST}{REQUEST_URI}" pattern="domain1/server/sdk/rest/" />
                    </conditions>
                </rule>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文