php - 当没有这样的文件时,什么 apache 配置导致 domain.com/index.php/abcdefg 工作?

标签 php linux apache .htaccess configuration

我有一个页面:

http://domain.com/index.php

但奇怪的是,以下 urls 也可以正常工作并呈现相同的页面:

http://domain.com/index.php/abcd
http://domain.com/index.php/gefe

等等..

很明显,这似乎是一个搞砸了的 regex 配置。但奇怪的是,即使我删除了 .htaccess 文件,这些 url 仍然有效。

现在,我只能责怪我的 apache 配置,但一切似乎都符合预期。

我的 apache 配置:

<VirtualHost *:80>
    # Server name
    ServerName domain.com
    # Document root
    DocumentRoot /path/to/source

    <Directory />
        Options FollowSymLinks
    </Directory>
    <Directory /path/to/source>
        AllowOverride All
        Options Indexes FollowSymLinks MultiViews
        Order allow,deny
        allow from all
    </Directory>

    LogLevel error

    # Logs
    ErrorLog ${APACHE_LOG_DIR}/domain_error.log
    CustomLog ${APACHE_LOG_DIR}/domain_access.log combined

    RewriteMap  lc int:tolower
</VirtualHost>

谁能指出错误?

最佳答案

它叫做 PATH_INFO。 Apache 将从左到右扫描 URL。只要找到匹配的目录,它就会继续执行文档根目录,直到用完目录或找到匹配的脚本。之后,任何额外的“路径”信息都会变成 PATH_INFO,例如

你有一个网站,在/a/b/c 的真实存在的目录结构中有一个名为“foo.php”的脚本,所以

http://example.com/a/b/c/foo.php

是一个有效的 url。

在那种情况下,

http://example.com/a/b/c/foo.php/bar/baz/bip/bop/boop
                                ^^^^^^^^^^^^^^^^^^^^^-- path info

向上阅读:http://httpd.apache.org/docs/current/mod/core.html#acceptpathinfo

关于php - 当没有这样的文件时,什么 apache 配置导致 domain.com/index.php/abcdefg 工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16924344/

相关文章:

linux - 从 bash 中的文件列表中删除前缀

php 脚本在 CentOS6.5 上输出为文本

php - 为什么 Apache 在 200 秒后向 PHP POST 请求返回零内容长度?

php - Google Recaptcha 错误,登录时未完成拼图但显示勾号

php - Symfony 多对多连接

windows - Vim:Mac 与 Linux ^M 问题

linux - 链接时未定义对符号 'socket@GLIBC_2.4' 的引用

apache - apache hadoop,hbase和nutch组件分布,用于4个服务器集群

php - 在 PHP 中,sleep 和 usleep 的内部行为是否不同?

php - Smarty {if $foo} 相当于 isset()