简体   繁体   English

IIS 重定向映射不适用于根目标

[英]IIS redirect maps not working for root destination

I am having some trouble getting rewrite pas to work correctly when I point the destination to root.当我将目标指向 root 时,我在让 rewrite pas 正常工作时遇到了一些麻烦。

If I point at a /page/ destination t seems to work correctly, but if I point at / it does not.如果我指向 /page/ 目的地 t 似乎可以正常工作,但如果我指向 / 则不会。 Below is what I have in my web.config以下是我在 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>

The 1st one works第一个作品
The 2nd, 3rd, 4th does not work第二、第三、第四个不起作用
The 5th, 6th, 7th, 8th and 9th does work第 5、6、7、8 和 9 号确实有效
The 10th or last one does not第 10 个或最后一个没有

I have edited a few obvious spots for privacy IIS 8.5我为 IIS 8.5 的隐私编辑了一些明显的地方

The 1st works because it matches 1st rule.第一个有效,因为它匹配第一条规则。

The 2nd doesn't work because you didn't set default document.第二个不起作用,因为您没有设置默认文档。 It matches 1st rule ,if you set default document, it will rewrite to http://localhost:xx/ and display default document.它匹配第一条规则,如果您设置默认文档,它将重写为 http://localhost:xx/ 并显示默认文档。

The 3rd and 4th match 1st rule, both rewrite to http://localhsot:xx/index.php第三条和第四条匹配第一条规则,都改写为http://localhsot:xx/index.php

The 5th,6th,7th,8th all match 1st and 2nd rule, but rewrite to http://localhsot:xx/index.php//”value” and display index.php.第 5、6、7、8 条都符合第 1 条和第 2 条规则,但重写为 http://localhsot:xx/index.php//”value” 并显示 index.php。

The 9th matched 1st rule and rewrite to http://localhsot:xx/ article.aspx?id=1&title=some-title.第 9 条匹配第 1 条规则并重写为 http://localhsot:xx/article.aspx?id=1&title=some-title。

The 10th is the same as the 2nd.第 10 次与第 2 次相同。

You can open fail request tracing which will record the entire rewriting process including whether it meets the rules and whether to rewrite.您可以打开失败请求跟踪,它会记录整个重写过程,包括是否符合规则以及是否重写。

I apologize I had not posted the beginning of the config file.我很抱歉我没有发布配置文件的开头。 I assumed everyone would understand default document has been set, since the entire site would not load without it.我假设每个人都会理解默认文档已被设置,因为没有它整个站点将无法加载。

Here is the beginning part of the web.config I had not posted earlier这是我之前没有发布的 web.config 的开始部分

    <configuration>
  <system.webServer>
    <defaultDocument>
      <files>
        <add value="index.php" />
      </files>
    </defaultDocument>
    <rewrite>
    <rewriteMap name="StaticRewrites">

I appreciate any help in this matter, and know I must be missing something simple since most rules do in fact work我感谢在这件事上的任何帮助,并且知道我必须遗漏一些简单的东西,因为大多数规则实际上都有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM