如何使用Apache 2在子目录中自动加载index.html

gle*_*don 7 apache2

我在使用Apache 2的子目录中自动加载index.html时出现问题.自动加载index.html适用于根目录.

你看,为了使事情变得通用,我的Web应用程序被编写成每个模块都驻留在它自己的子目录中.每个文件夹有3个文件 - 前端的index.html(包含html + javascript),后端的index.php(包含访问数据库的php代码)和index.css的样式.

因此,要访问Web应用程序中的各个模块:

[概述模块] - http://xyz.com/overview?id=1234567890

[详情模块] - http://xyz.com/details?id=1234567890

如果没有子目录的自动加载机制,则无法实现上述目标.

我将不胜感激任何帮助.非常感谢!

gle*_*don 9

最后与同事解决了这个问题.

httpd.conf中指定的默认DirectoryIndex对我们不起作用.即使我们的序列是'index.html'然后是'index.php',Apache2也会首先提供'index.php'.只有当'index.php'不存在于同一文件夹中时,才会提供'index.html'.

我们找到了两种方法来克服这个问题

假设你的doc root是'/ 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.)

重新启动Web服务器.

希望这可以帮助别人.谢谢!