redirect - IIS 重定向映射不适用于根目标
问题描述
当我将目的地指向根目录时,我在让重写过程正常工作时遇到了一些麻烦。
如果我指向 /page/ 目标 t 似乎可以正常工作,但如果我指向 / 它不会。以下是我的 web.config 中的内容
<rewrite>
<rewriteMaps>
<rewriteMap name="StaticRewrites">
<add key="/1" value="/article.aspx?id=1&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&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 编辑了一些明显的位置
解决方案
第一个有效,因为它匹配第一条规则。
第二个不起作用,因为您没有设置默认文档。它符合第一条规则,如果您设置默认文档,它将重写为 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号一样。
您可以打开失败请求跟踪,它将记录整个重写过程,包括是否符合规则以及是否重写。
推荐阅读
- algorithm - 行进立方体 - 获得倾斜的表面
- python - Selenium Python 在 Google Colab 中不起作用
- asp.net - 使用带有模式优先方法的 hotchocolate 过滤器
- python - 从 XML 文件创建 DataFrame
- c - 为什么我的动态分配数组只包含一个结果?
- android - 每当我尝试在片段中隐藏工具栏时,应用程序首先更改工具栏标题,然后才隐藏自身
- wordpress - 如何通过 wordpress 为我的网站创建简码
- c - 如何使用 OpenMP 在线程之间平等地并行化两个 for 语句?
- swift - 在 Swift 中初始化 'top' 结构
- javascript - select2:更改选项时清除多选下拉选定字段和另一个相关的多选下拉列表