在我的开发环境中,我使用php5.4的web内置web服务器,但似乎.htaccess无法正常工作。我找不到该服务器的文档。有人能告诉我是否有可能像apache一样使用htaccess和mod_rewrite?
非常感谢你
在我的开发环境中,我使用php5.4的web内置web服务器,但似乎.htaccess无法正常工作。我找不到该服务器的文档。有人能告诉我是否有可能像apache一样使用htaccess和mod_rewrite?
非常感谢你
正如我在评论中提到的那样,当前目录默认是您的webroot。此网络服务器也不支持 .htaccess
。
你会找到一个 很好的解释 关于你的问题。
让服务器运行
默认情况下,当前目录是您的webroot,您现在可以 请求这里的任何文件,并以通常的方式运行PHP
要么
像Apache重写一样的路由请求
我正在寻找的一个直接功能是能力 将所有传入的请求重定向到index.php,我通常会这样做 .htaccess文件。这个网络服务器不支持那些(虽然我的 好朋友约什创造了一些非常接近的东西但是确实如此 支持路由文件。
我不是这样做的粉丝,但是我已经通过软件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]));
}
}
}
}
它适用于应用PHP设置 .htaccess
到PHP CLI脚本,但我认为它也适用于PHP的内置Web服务器。