首页 > 解决方案 > IIS 重定向映射不适用于根目标

问题描述

当我将目的地指向根目录时,我在让重写过程正常工作时遇到了一些麻烦。

如果我指向 /page/ 目标 t 似乎可以正常工作,但如果我指向 / 它不会。以下是我的 web.config 中的内容

    <rewrite>
    <rewriteMaps>
        <rewriteMap name="StaticRewrites">
            <add key="/1" value="/article.aspx?id=1&amp;title=some-title" />
            <add key="/random_page.htm" value="/" />
            <add key="/friends.htm" value="index.php" />
            <add key="/page_2.htm" value="/index.php" />
            <add key="/some_other_page.htm" value="/some_other_page/" />
            <add key="/some_page_test.htm" value="/test21.php" />
            <add key="/2nd_page_test.htm" value="/test.txt" />
            <add key="/3rd_page_test" value="/test1.htm" />
            <add key="/4th_page_test.htm" value="article.aspx?id=1&amp;title=some-title" />
            <add key="/root_page_again.htm" value="/" />
        </rewriteMap>
</rewriteMaps>
<rules>     
    <rule name="Rewrite rule1 for StaticRewrites">
            <match url="(.*)" />
            <conditions>
                <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
            </conditions>
            <action type="Rewrite" url="{C:1}" appendQueryString="false" />
    </rule>
    <rule name="WordPress: http://123.123.12.123" patternSyntax="Wildcard">
        <match url="*" />
        <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
            <action type="Rewrite" url="index.php/{R:0}" />
    </rule>     
</rules>
</rewrite>

第 1 个有效
第 2、3、4 个无效
第 5、6、7、8 和 9 个有效
第 10 个或最后一个无效

我为隐私 IIS 8.5 编辑了一些明显的位置

标签: redirectiis-8http-redirectiis-8.5iis-modules

解决方案


第一个有效,因为它匹配第一条规则。

第二个不起作用,因为您没有设置默认文档。它符合第一条规则,如果您设置默认文档,它将重写为 http://localhost:xx/ 并显示默认文档。

第 3 条和第 4 条匹配第 1 条规则,都重写为 http://localhsot:xx/index.php

第 5、6、7、8 条都匹配第 1 条和第 2 条规则,但改写为 http://localhsot:xx/index.php//“value”并显示 index.php。

第 9 条匹配第 1 条规则并重写为 http://localhsot:xx/article.aspx?id=1&title=some-title。

10号和2号一样。

您可以打开失败请求跟踪,它将记录整个重写过程,包括是否符合规则以及是否重写。


推荐阅读