【问题标题】:URL rewrite between 2 urls that are being handled by the same web.config由同一 web.config 处理的 2 个 url 之间的 URL 重写
【发布时间】:2013-09-19 22:18:10
【问题描述】:

当我尝试实现我创建的这个移动重定向时,我得到了一个重定向循环:

<rewrite>
    <rules>
        <rule name="Mobile Rewrite" patternSyntax="ECMAScript" stopProcessing="true">
            <match url=".*" ignoreCase="true" negate="false" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{HTTP_HOST}" pattern="website.com.au" />
                <add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone" />
            </conditions>
            <action type="Redirect" url="http://mwebsite.com.au" appendQueryString="false" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>

这是一个问题,mwebsite.com.au 与 website.com.au 被分配到相同的 web.config,因此它们由相同的 web.config 处理。这是我正在处理的 .net 应用程序处理请求的方式(我无法将它们拆分,它们必须通过这个 1 web.config)

我已通过将 mwebsite.com.au 替换为 google.com.au 对此进行了测试,它运行良好,但由于某种原因,当 URLREWRITE 必须通过相同的规则注入 mwebsite.com.au 时,它无法处理请求。

任何帮助都会很棒。

【问题讨论】:

    标签: iis redirect url-rewriting web-config


    【解决方案1】:

    您的规则基本上是说:如果{HTTP_HOST} 包含website.com.au 并且{HTTP_USER_AGENT} 包含midpmobilephone 中的任何一个,则重定向到http://mwebsite.com.au
    你可以猜到,http://mwebsite.com.au 包含website.com.au

    要解决此问题,只需使用模式^website.com.au 告诉您的条件,它应该以website.com.au 开头。

    所以你的规则会变成:

    <rewrite>
        <rules>
            <rule name="Mobile Rewrite" patternSyntax="ECMAScript" stopProcessing="true">
                <match url=".*" ignoreCase="true" negate="false" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{HTTP_HOST}" pattern="^website.com.au" />
                    <add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone" />
                </conditions>
                <action type="Redirect" url="http://mwebsite.com.au" appendQueryString="false" redirectType="Permanent" />
            </rule>
        </rules>
    </rewrite>
    

    【讨论】:

    • 你先生,真棒。这是一件很简单的事情。非常感谢。
    • 不客气!我看到你最近订阅了这个网站,所以如果你没有看到this link,它解释了为什么以及如何你应该接受或不接受答案! :)
    • 啊谢谢@cheesemacfly,我没有收到您的评论通知,只是现在才阅读。我已经勾选了答案,谢谢!
    猜你喜欢
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-13
    • 1970-01-01
    • 2017-08-23
    • 2012-06-04
    相关资源
    最近更新 更多