【问题标题】:Prevent IIS7 rewrite from adding "index.php" to path on redirect?防止IIS7重写将“index.php”添加到重定向路径?
【发布时间】:2010-10-24 19:57:34
【问题描述】:

我正在尝试使用 PHP5 (fastcgi) 在 IIS7 上为 Wordpress MU 2.7 配置 rewrite 规则。

目前我在 Web.config 中只有以下重写规则:

         <rule name="Canonical Host Name" stopProcessing="true">
             <match url="(.*)" />
             <conditions logicalGrouping="MatchAll">
                 <add input="{HTTP_HOST}" negate="true"
                      pattern="^subdomain\.example\.com$" />
             </conditions>
             <action type="Redirect"
                     url="http://subdomain.example.com/{R:1}"
                     redirectType="Permanent" />
         </rule>

当我输入一个 URL(见下文)时,它会重定向到正确的主机名,但由于某种原因,它会在路径前加上 index.php/

url: `http://subdomain/my/path/123`
redirects to: `http://subdomain.example.com/index.php/my/path/123`
should redirect to: `http://subdomain.example.com/my/path/123`

有谁知道为什么会这样以及如何防止这种情况发生?

我是否缺少某个服务器设置或什么...? php.ini? web.config 规则?还是只是我的重写规则有问题?

编辑:这个问题似乎与 Wordpress 的永久链接结构无关!如果我删除重定向index.php,行为是相同的。我认为没有任何 PHP 代码正在运行……这必须是更高级别的。

【问题讨论】:

  • 您在 Wordpress 中对永久链接结构有哪些设置?
  • 这有关系吗?目前我仍然得到两个 url 的 404 错误,因为我已经排除了所有其他规则并且没有明显找到子文件夹;还没有 php 正在运行。

标签: php iis iis-7 rewrite


【解决方案1】:

默认情况下(我认为)Wordpress 将友好的永久链接格式化为 index.php/path/to/post,因为这模拟了重写,而不需要服务器支持重写。这可以解释为什么你的重写是这样的——他们在重写之前有 index.php。

【讨论】:

  • 我认为没有任何 php 代码(wordpress)运行。如果我删除/重命名 index.php 我仍然有同样的问题。除此之外,永久链接结构已经设置为路径中没有“index.php”的版本...
【解决方案2】:

您可以通过 WordPress 配置中的changing the Permalink structure 选项来防止它发生。

【讨论】:

  • 这也是我的第一个想法,但它似乎处于更高的水平......永久链接结构已经设置为路径中没有 /index.php 的版本。
猜你喜欢
  • 2021-06-25
  • 1970-01-01
  • 2014-01-27
  • 1970-01-01
  • 2013-07-18
  • 1970-01-01
  • 2014-09-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多