大网数据广告活动
服务器运维问答

apache2 custom error, when a directory is empty

· 52CE 我爱测

Usually, when a directory has no index.html file in it, apache just displays a page which says "Index of /subdir" at the top and lists all the files. How is it possible to instead of this show a custom error page? Preferably some…

问题原文

原帖链接 · OfficialCRUGG · CC BY-SA 4.0

Usually, when a directory has no index.html file in it, apache just displays a page which says "Index of /subdir" at the top and lists all the files. How is it possible to instead of this show a custom error page? Preferably something I can put in my .htaccess File

已采纳解答

原帖链接 · wurtel · CC BY-SA 4.0

By default there will be configuration line such as the following in your apache config:

DirectoryIndex index.html index.php index.cgi

This defines the order in which those files are searched for to present the content for a directory when that directory is requested without any file part. If not found, and the autoindex feature is enabled, you will get the directory contents listed.

However, it is also possible to define an absolute path for DirectoryIndex, such as:

DirectoryIndex index.html /default/index.html

Now, if there is no index.html in a directory, the contents of /default/index.html (relative to the DocumentRoot) will be used, which I believe is exactly what you're asking for.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-05-07)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。