【问题标题】:Why is my url redirect command not working properly?为什么我的 url 重定向命令无法正常工作?
【发布时间】:2020-07-13 07:34:33
【问题描述】:

我有一个内部网站http://example/。我需要将所有流量重定向到新的内部站点 (http://newexample/)除了以下两个子文件夹中的所有内容:

  1. /Admin/
  2. /API/Test/

这是我尝试过的:

<rewrite>
    <rules>
        <rule name="Redirect Example" enabled="true" stopProcessing="true">
            <match url="(.*)" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{REQUEST_URI}" pattern="^Admin/.*" negate="true"/>
                    <add input="{REQUEST_URI}" pattern="^API/Test/.*" negate="true"/>                       
            </conditions>
            <action type="Redirect" url="http://newexample/" appendQueryString="true" redirectType="Found" />
        </rule>
    </rules>
</rewrite>

我遇到的问题是它正在重定向所有包括两个子文件夹中的内容。我还尝试删除导致没有页面被重定向的negate 属性。我在这里做错了什么?

【问题讨论】:

标签: redirect url-rewriting iis-7.5


【解决方案1】:

您只需对规则进行一些小的更改。

<rule name="Redirect Example" enabled="true" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                    <add input="{REQUEST_URI}" pattern="^/Admin/.*" negate="true" />
                    <add input="{REQUEST_URI}" pattern="^/API/Test/.*" negate="true" />                       
        </conditions>
        <action type="Redirect" url="http://newexample/" appendQueryString="true" redirectType="Found" />
    </rule>

【讨论】:

    【解决方案2】:

    我发布了我找到的解决方案,希望以后能对某人有所帮助。这一切都与&lt;match url="(^$)" /&gt;add 元素上的pattern 属性有关。仔细观察非常细微的差异:

    我变了:

    <rewrite>
        <rules>
            <rule name="Redirect Example" enabled="true" stopProcessing="true">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_URI}" pattern="^Admin/.*" negate="true"/>
                        <add input="{REQUEST_URI}" pattern="^API/Test/.*" negate="true"/>                       
                </conditions>
                <action type="Redirect" url="http://newexample/" appendQueryString="true" redirectType="Found" />
            </rule>
        </rules>
    </rewrite>
    

    <rewrite>
        <rules>
            <rule name="Redirect Example" enabled="true" stopProcessing="true">
                <match url="(^$)" />
                <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                        <add input="{REQUEST_URI}" pattern="^Admin$" negate="true"/>
                        <add input="{REQUEST_URI}" pattern="^API/Test$.*" negate="true"/>               
                </conditions>
                <action type="Redirect" url="http://newexample/" appendQueryString="true" redirectType="Found" />
            </rule>
        </rules>
    </rewrite>
    

    【讨论】:

      猜你喜欢
      • 2017-09-23
      • 2019-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-25
      • 1970-01-01
      • 2015-08-09
      • 2014-07-01
      相关资源
      最近更新 更多