简体   繁体   English

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

[英]Change the default index.php/index.html to something else on PHP Server

I am using the server environment that comes with PHP as my development server. 我正在使用PHP附带的服务器环境作为开发服务器。 Ie I'm using the following to run websites. 即我正在使用以下内容来运行网站。

php -S localhost:3000

I want it to look for something other than index.php or index.html as the default for the particular folder (something like source.html). 我希望它查找index.php或index.html以外的其他内容作为特定文件夹的默认名称(类似于source.html)。 I know I could do this on Apache. 我知道我可以在Apache上执行此操作。 But is there a way to do the same with the above mentioned PHP server? 但是,有没有办法对上述PHP服务器执行相同的操作?

Don't edit your Apache config files (like .htaccess). 不要编辑您的Apache配置文件(如.htaccess)。 The PHP inbuilt server does not use them (unless you use a third part solution ). PHP内置服务器不使用它们(除非您使用第三方解决方案 )。

Have you tried php -S localhost:3000 source.html ? 您是否尝试过php -S localhost:3000 source.html

Or when your index is in another directory: 或当索引位于另一个目录中时:

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

Using the front controller pattern: 使用前端控制器模式:

In a more advanced use case in which you might want to route all request except your static image, js and css files to your front controller (say index.php), you need to create a separate routing script, router.php . 在更高级的用例中,您可能希望将除静态映像,js和css文件以外的所有请求路由到前端控制器(例如index.php),您需要创建一个单独的路由脚本router.php

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

And then run it with: 然后运行:

php -S localhost:3000 -t docroot docroot\router.php

Rewriting requests to use a default index file: 重写请求以使用默认索引文件:

Ok, I think what you want is to server every file at its original location. 好的,我想您想要的是将每个文件保存在其原始位置。 Only when accessing a directory, the source.html in that directory should be used as default file. 仅当访问目录时,该目录中的source.html才应用作默认文件。

Change the router.php to: 将router.php更改为:

if (is_dir(__DIR__ . $_SERVER['PHP_SELF'])) {
    include __DIR__ . $_SERVER['PHP_SELF'] . '/source.html';
} else {
    // Try to load file directly from disk.
    return false;
}

you could change it on the file httpd-vhosts.conf 您可以在文件httpd-vhosts.conf上进行更改

// here the configuration of your virtual host Documentroot etc //这里是虚拟主机Documentroot等的配置

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

or you could do the same thing in the file http.conf 或者您可以在文件http.conf中执行相同的操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM