How to automatically load index.html into subdirectories with Apache 2

I have a problem with automatically loading index.html in subdirectories with Apache 2. Automatically loading index.html works fine for the root directory.

You see, in order to do everything in common, my web application is written so that each module is in its own subdirectory. Each folder has 3 files - index.html for the interface (contains html + javascript), index.php for the backend (contains php code to access the database) and index.css for styling.

Therefore, to access the various modules in the web application:

[Review module] - http://xyz.com/overview?id=1234567890

[Detailed module] - http://xyz.com/details?id=1234567890

Without an automatic download mechanism for subdirectories, the above would not be possible.

I would appreciate any help. Many thanks!

+6
source share
1 answer

Finally, resolved this with a colleague.

By default, DirectoryIndex specified in httpd.conf does not work for us. Although our sequence is "index.html" and then "index.php", Apache2 will work with index.php first. Only when "index.php" is not present in the same folder, and then "index.html" is served.

We found 2 ways to overcome this:

Assuming your doc root is '/ var / www / html',

  [Method 1]
 1. Add a .htaccess to the root directory of your web app (eg / var / www / html / myapp).
 2. Add the line 'DirectoryIndex index.html' to the .htaccess.
 3. In httpd.conf, set 'AllowOverride' to 'All' under <Directory '/ var / www / html'>.
  [Method 2]
 1. In httpd.conf, add 'DirectoryIndex index.html' under <Directory 'var / www / html'>.
 (note: this 'DirectoryIndex' is different from the default DirectoryIndex that is 
 not enclosed within any tag.)

Restart the web server.

Hope this helps someone. Thanks!

+8
source

Source: https://habr.com/ru/post/890887/


All Articles