11

在我的开发环境中,我使用 php5.4 的 web 内置 web 服务器,但 .htaccess 似乎无法正常工作。我找不到该服务器的文档。有人能告诉我是否可以像 apache 一样使用 htaccess 和 mod_rewrite 吗?

非常感谢

4

2 回答 2

12

正如我在评论中提到的,当前目录默认是您的 webroot。此网络服务器也不支持.htaccess.

你会在这里找到关于你的问题的一个很好的解释。

让服务器运行

默认情况下,当前目录是您的 webroot,您现在可以请求此处的任何文件,并以通常的方式运行 PHP

或者

像 Apache Rewrite 这样的路由请求

我一直在寻找的一个直接功能是将所有传入请求重定向到 index.php 的能力,我通常使用 .htaccess 文件执行此操作。这个网络服务器不支持这些(尽管我的好朋友 Josh 已经创建了一些非常接近的东西),但它确实支持路由文件。

于 2012-09-24T11:58:40.757 回答
0

我不是这样做的粉丝,但我已经看到软件 Magento 在野外这样做了:

/**
 * Parse .htaccess file and apply php settings to shell script
 *
 */
protected function _applyPhpVariables()
{
    $htaccess = $this->_getRootPath() . '.htaccess';
    if (file_exists($htaccess)) {
        // parse htaccess file
        $data = file_get_contents($htaccess);
        $matches = array();
        preg_match_all('#^\s+?php_value\s+([a-z_]+)\s+(.+)$#siUm', $data, $matches, PREG_SET_ORDER);
        if ($matches) {
            foreach ($matches as $match) {
                @ini_set($match[1], str_replace("\r", '', $match[2]));
            }
        }
        preg_match_all('#^\s+?php_flag\s+([a-z_]+)\s+(.+)$#siUm', $data, $matches, PREG_SET_ORDER);
        if ($matches) {
            foreach ($matches as $match) {
                @ini_set($match[1], str_replace("\r", '', $match[2]));
            }
        }
    }
}

https://github.com/OpenMage/magento-mirror/blob/1b7c8107492ddea9d480152bdc81908befd0795c/shell/abstract.php#L110-L134

它旨在将 PHP 设置应用.htaccess到 PHP CLI 脚本,但我想它也应该适用于 PHP 的内置 Web 服务器。

于 2018-06-06T07:20:40.123 回答