【问题标题】:Something rewrites rules for php when Apache mod_rewrite module is disabled当 Apache mod_rewrite 模块被禁用时,某些东西会重写 php 的规则
【发布时间】:2010-09-19 23:17:55
【问题描述】:

我运行以下网址:

http://localsite/index.php/foo/bar

index.php 被执行并输出变量:

$_SERVER[SCRIPT_FILENAME] = E:/path/to/file/index.php

Apache 中的 mod_rewrite 已禁用。

谁重写了规则?
或者会发生什么?

index.php 是如何找到的?为什么 apache 决定运行它?

我的配置: Windows Vista、Apache Apache/2.2.14 (Win32) PHP/5.3.1(带 php 模块)。

(问题实际上是在 mod_rewrite 之前重写了规则 - 这是启用 mod_rewrite 时。这导致 RewriteCond %{REQUEST_FILENAME} !-f 始终为 false,因为 /foo/bar 在 RewriteCond 之前被修剪)。

【问题讨论】:

    标签: php apache mod-rewrite


    【解决方案1】:

    这是由AcceptPathInfo Apache 指令引起的。

    它处理所有事情

    http://localsite/index.php
    

    作为资源,并放置

    /foo/bar
    

    进入$_SERVER["PATH_INFO"] 变量。

    当mod_rewrite 不可用时,它有时被用作穷人的 URL 重写器 - 缺点是在正常配置中,URL 中的某处必须有一个 .php。

    您的选择是关闭此功能,或使用不同的 URL - 取决于您的情况。

    【讨论】:

    • 我真的很难意识到其他东西也在重写 url。谢谢!
    • 这不是重写 - 您对 URL 的解析方式有错误的理解。有关详细信息,请参阅rfc-editor.org/rfc/rfc3875.txt中的第 3.2 节
    【解决方案2】:

    也许你应该使用 $_SERVER[REQUEST_URI] 代替,afaik,SCRIPT_FILENAME 告诉你 php 是从哪个文件开始的。

    【讨论】:

      猜你喜欢
      • 2011-04-02
      • 2013-09-08
      • 2012-10-10
      • 1970-01-01
      • 2023-03-18
      • 2011-10-28
      • 2010-11-09
      • 1970-01-01
      • 2012-07-22
      相关资源
      最近更新 更多