Mobile app version of vmapp.org
Login or Join
Eichhorn148

: Using one index file in all directories and subdirectories I have an index.php file, which processes content of a directory it is located in and renders output to the browser. The problem is

@Eichhorn148

Posted in: #Apache #Index #Nginx #Webserver

I have an index.php file, which processes content of a directory it is located in and renders output to the browser.

The problem is that the directory structure it is supposed to serve is rather complex, with many directories and subdirectories. I don't feel like putting a copy of index.php in each and every subdirectory.

I know I can use symlinks on systems that support them but it's still not a human's job to traverse the whole hierarchy and place links to the index file in question if no other is present. Also, not all systems actually support symbolic linking.

Is there a method to tell the webserver (Apache, nginx, ..) that if an index file is not present in a requested directory then it should use the specified index.php located elsewhere?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Eichhorn148

2 Comments

Sorted by latest first Latest Oldest Best

 

@Ogunnowo487

Is there a method to tell the webserver (Apache, nginx, ..) that if an index file is not present in a directory under document root, then it should use the specified index.php located elsewhere?


Yes, on Apache you can control this with the DirectoryIndex directive in your Apache config (or .htaccess file). For example:

DirectoryIndex index.php /index.php


When requesting a filesystem directory, this will serve either index.php in that directory, if it exists, otherwise /index.php will be served (index.php in the document root).

Nginx appears to have a similar directive called simply index.
Reference: serverfault.com/a/402949/49157

10% popularity Vote Up Vote Down


 

@Murray432

I understand what you are asking, but cannot figure out why you would need an index.php file in every directory (if typical php application programming practices are followed).

If you have to refer to the root index.php file from every sub-directory, mod_rewrite is the easiest way at the server level. This isn't server agnostic, as you may be asking, but see this article for examples on how to get the server to always refer to the index.php file: stackoverflow.com/questions/8595964/redirect-all-traffic-to-index-php-using-mod-rewrite

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme