将默认的index.php / index.html更改为PHP Server上的其他内容

时间:2015-01-12 11:05:33

标签: php webserver

我使用PHP附带的服务器环境作为我的开发服务器。 即我正在使用以下内容来运行网站。

php -S localhost:3000

我希望它能找到index.php或index.html以外的东西作为特定文件夹的默认值(类似于source.html)。我知道我可以在Apache上做到这一点。但有没有办法对上面提到的PHP服务器做同样的事情?

2 个答案:

答案 0 :(得分:0)

不要编辑Apache配置文件(例如.htaccess)。 PHP内置服务器不使用它们(除非您使用third part solution)。

您是否尝试过php -S localhost:3000 source.html

或者当您的索引位于另一个目录中时:

php -S localhost:3000 -t docroot docroot\source.html

使用前端控制器模式:

在一个更高级的用例中,您可能希望将除静态图像,js和css文件之外的所有请求路由到前端控制器(例如index.php),您需要创建一个单独的路由脚本{{1 }}

router.php

然后运行:

if (preg_match('/\.(?:png|jpg|jpeg|css|js)$/', $_SERVER['REQUEST_URI'])) {
    return false;
} else {
    include __DIR__ . '/index.php';
}

重写使用默认索引文件的请求:

好的,我认为您想要的是为每个文件服务于其原始位置。仅在访问目录时,该目录中的php -S localhost:3000 -t docroot docroot\router.php 应用作默认文件。

将router.php更改为:

source.html

答案 1 :(得分:-3)

你可以在文件httpd-vhosts.conf

上更改它

     //这里是虚拟主机Documentroot等的配置

<IfModule dir_module>
    DirectoryIndex index.php source.html test.php
</IfModule>

或者你可以在http.conf文件

中做同样的事情