Directory indexing is Apache’s behaviour of listing a folder’s contents when no index file is present — the “Index of /” page. On a production server you almost always want it off: an exposed listing leaks filenames, backups, and config files to anyone who guesses a URL. cPanel gives you three levels to control it: a single folder through the Indexes tool or .htaccess, an account through its document root, and every site through the server-wide default. This is a routine hardening task; the goal is to make “no index file” return a clean 403 instead of a public directory tree.
What’s happening
When Apache resolves a request to a directory and finds no DirectoryIndex match (index.html, index.php, …), the Options Indexes directive decides what happens: with Indexes on it generates a listing; with Indexes off it returns 403 Forbidden. The directive can be set at three scopes, with the most specific winning: a server-wide default in the Apache configuration, a per-account or per-folder .htaccess (Options -Indexes), and cPanel’s per-folder Indexes UI, which writes the equivalent setting.
cPanel’s default for new accounts is typically to disable indexing, but the setting drifts: a copied .htaccess re-enables it, an inherited server was configured with it on, or a developer turned it on for one folder and it now exposes more than intended. Controlling it deliberately at the right scope — and confirming with a request — is the reliable approach, rather than assuming the default is safe.
How to verify
Check what Apache currently returns for a directory with no index file, and where indexing is set.
# What does a bare directory with no index file return?
curl -sI https://example.com/uploads/ | head -1
curl -s https://example.com/uploads/ | grep -i 'Index of' # a hit means indexing is ON
# Indexing directives in the account's .htaccess files
grep -rniE 'options.*indexes' /home/<cpaneluser>/public_html/
find /home/<cpaneluser>/public_html -name .htaccess
Check the server-wide default if you intend to set it globally.
# Server-wide Options live in the Apache main config / includes
grep -rniE 'options.*indexes' /etc/apache2/conf/httpd.conf /etc/apache2/conf.d/ 2>/dev/null
# Validate config after any global change
apachectl configtest
The fix
- Disable a single folder with cPanel’s Indexes tool — cPanel » Advanced » Indexes lists the account’s folders; set the target folder to No Indexing. cPanel writes the equivalent directive without you editing files by hand. This is the simplest per-folder control and the right tool for a one-off.
- Disable per account with .htaccess — add
Options -Indexesto the document root’s.htaccess. Because.htaccessapplies to the whole tree beneath it, this turns off indexing for the entire account in one line, so any folder lacking an index file returns 403. This is the line you want on essentially every production site. - Keep an index file as defense in depth — even with indexing off, dropping an empty
index.htmlin sensitive folders (uploads, includes, backups) is a cheap second layer. Some setups or future.htaccessedits could re-enable indexing; an index file means there is nothing to list regardless. - Set the server-wide default — to make “off” the default for every vhost, disable
Indexesin the global directory options via WHM » Apache Configuration » Global Configuration (or the Include Editor with a<Directory>block settingOptions -Indexes). Runapachectl configtestthen rebuild/restart. This means new accounts inherit the safe behaviour without per-account work. - Audit and remove stray +Indexes —
grepmay findOptions +Indexesleft in an.htaccessfrom a copied site or an old “file share” folder. Change it to-Indexesor remove it, after confirming which directory it governs — a few setups intentionally list a public downloads folder, so check before flipping every one. - Mind AllowOverride —
Options -Indexesin.htaccessonly takes effect if the account’sAllowOverridepermitsOptions(orIndexes). If the directive is ignored, set it server-side instead, or adjustAllowOverridefor the account (see the AllowOverride reference). On a locked-down server, the cPanel Indexes tool or the global config is the dependable route. - Treat any prior exposure as a leak — if a folder was listing before you closed it, sensitive files may already have been seen or indexed by bots. After disabling indexing, review what was exposed and rotate any credentials that sat in a downloadable file; closing the listing does not un-expose what was already crawled.
After setting the directive at the scope you chose, request a directory with no index file and confirm you get a 403 (or the site), never “Index of /” — a 403 on an empty folder is the verifiable proof indexing is off, far more reliable than assuming the default. Stack Harbor handles cPanel directory-indexing policy and hardening under cPanel/WHM management — start a conversation.