.htaccess DirectoryIndex不起作用

Zen*_*eno 9 apache .htaccess

我的public_html文件夹(Apache)中有两个索引文件,index.html和index.php

默认情况下,Apache似乎将流量定向到index.php,因此我想将其更改为index.html.我在同一目录中添加了一个.htaccess文件:

DirectoryIndex index.html

但是当访问者访问网站(www.example.com/)时,他们仍然会被引导至index.php

为什么是这样?

bde*_*eta 11

对于仍在寻找答案的人 - 就像OP建议的那样,将以下行添加到.htaccess文件中:

DirectoryIndex index.php
Run Code Online (Sandbox Code Playgroud)

确保您的主机允许httpd.conf中的htaccess覆盖

AllowOverride All
Run Code Online (Sandbox Code Playgroud)

如果未启用,则必须与您的托管服务提供商联系.


ᴘᴀɴ*_*ᴛɪs 2

尝试这个:

DirectoryIndex index.html index.htm index.php index.php3
Run Code Online (Sandbox Code Playgroud)

优先级是从左到右,所以如果你碰巧都有 html 将被优先考虑