What is a directory listing?
If you open a folder address and the folder has no index.html or index.php, Apache may show a plain page that lists the files inside. That page is the directory listing. Apache is the web server program that sends your pages.
Use listings only for folders you want to share, such as downloads. For other folders, leave them off for safety.
Turn the listing on or off
Settings go in a file named .htaccess inside the folder. It is a small settings file that Apache reads for that folder. Back it up before editing.
Options +Indexes
This turns the listing on. Use Options -Indexes to turn it off.
Steps to change the style
- Log in to cPanel and open File Manager.
- Show hidden files from Settings.
- Go to the folder you want to share.
- Open or create
.htaccessand click Edit. - Add the lines you want from the list below.
- Save the file.
- Reload the folder address in your browser.
Useful settings
Options +Indexes
IndexOptions FancyIndexing HTMLTable NameWidth=* DescriptionWidth=*
IndexOptions FoldersFirst IgnoreCase
IndexIgnore .htaccess *.php
FancyIndexingadds icons and sortable columns.HTMLTableputs the list in a table.FoldersFirstshows folders before files.IndexIgnorehides files from the list.
Add your own header, footer and colors
- Create a file named
header.htmlwith a short title or welcome text. - Create a file named
footer.htmlwith any closing text. - Create a file named
style.csswith your colors and fonts. - Add these lines to
.htaccess:
HeaderName header.html
ReadmeName footer.html
IndexStyleSheet "/style.css"
These lines load your header, footer and stylesheet into the listing page. The stylesheet path is measured from your website root.
Quick recap
- A directory listing shows files when a folder has no index page.
- Use
.htaccessto turn it on and change its style. IndexOptions,HeaderNameandIndexStyleSheetchange the look.- Keep listings off for private folders.