I'm having problem auto-loading index.html in sub-directories with Apache 2. Auto-loading of index.html works fine for root directory.
You see, to make things generic, my web app is written such that each module resides in its own sub-directory. Each folder has 3 files - index.html for the front end (contains html + javascript), index.php for the backend (contains php code to access database) and index.css for styling.
Hence, to access the various modules in the web app:
[Overview module] - http://xyz.com/overview?id=1234567890
[Details module] - http://xyz.com/details?id=1234567890
Without the auto-load mechanism for sub-directories, the above would not be possible.
I would appreciate any help. Thanks much!
Finally resolved it with a colleague.
The default DirectoryIndex specified in httpd.conf didn't work for us. Even though our sequence is 'index.html' then 'index.php', Apache2 will serve out 'index.php' first. Only when 'index.php' is not present in the same folder, then 'index.html' is served out.
We found 2 ways to overcome that:
Assuming your doc root is '/var/www/html',
[Method 1] 1. Add a .htaccess to the root directory of your web app (e.g. /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 can help someone. Thanks!
You can use the following line in your .htaccess
file:
DirectoryIndex index.html
Works even if you don't control the server configuration (if you use Gitlab Pages for example).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With