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

寵の児 提交于 2020-02-08 07:10:05

问题


I am using the server environment that comes with PHP as my development server. I.e. 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). I know I could do this on Apache. But is there a way to do the same with the above mentioned PHP server?


回答1:


Don't edit your Apache config files (like .htaccess). The PHP inbuilt server does not use them (unless you use a third part solution).

Have you tried 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.

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.

Change the router.php to:

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



回答2:


you could change it on the file httpd-vhosts.conf

// here the configuration of your virtual host Documentroot etc

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

or you could do the same thing in the file http.conf



来源:https://stackoverflow.com/questions/27900562/change-the-default-index-php-index-html-to-something-else-on-php-server

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!