自动转到子目录索引页.htaccess 规则

Automatically go to subdirectory index page .htaccess rule

我希望当我像这样单击 link 时:<a href="settings/">Settings</a> 它将转到子目录,并加载 index.php。 当我现在尝试这个时,我得到一个 404 error

如果 link 是这样就可以工作:<a href="settings/index.php">Settings</a> 但我不想 url.

中的 index.php

有人知道我如何编写 .htaccess 规则来实现这一点吗?

.htaccess

DirectoryIndex index.php index.html

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ .php [NC,L]

哦,你刚刚提到.htaccess,现在我可以回答了。您只需要编辑 DirectoryIndex 指令。将此添加到您的 .htaccess

DirectoryIndex index.php index.html

我在回答之前添加了评论,因为您没有指定网络服务器。在您的评论提到 .htaccess 之后,它肯定是 apache,此解决方案适用于 apache。您可以编辑配置文件或将其添加到 .htaccess

这个指令告诉 apache 首先使用 index.php 作为目录索引,如果它找不到然后寻找 index.html