Updated: 22 October 2026 · Applies to: Apache with .htaccess support (AllowOverride enabled)
These four .htaccess directives control directory listings, their style, the default index file and custom error pages.
1. Allow or block directory listing
When a URL has no index file (index.html, index.htm, default.html, and so on), Apache shows a list of the folder's files and directories unless you turn that off.
To allow listing:
Options +Indexes
To block it and return a 403 error instead:
Options -Indexes
2. Style of the file and folder list
To show icons, file size and modification date alongside each entry:
IndexOptions +FancyIndexing
To go back to the plain list:
IndexOptions -FancyIndexing
3. Change the default index file
To use a different file as the default page instead of index.html/index.htm/default.html:
DirectoryIndex newindex.html
4. Custom error pages
By default, Apache shows its own generic page for errors such as a missing file. To use your own page or message instead, add an ErrorDocument line with the 3-digit status code:
ErrorDocument 404 /404.html
This shows 404.html when the requested document is not found. You can use a plain text message instead of a file:
ErrorDocument 404 "The document was not found"
Other common codes to customise this way:
- 401: authorization required (a password-protected area).
- 403: forbidden (access to that part of the site is blocked).
- 500: internal server error, usually wrong file permissions or a mistake earlier in .htaccess.