Enabling/Disabling Directory Indexes
52 vues
Website Management
<h3>What Are Directory Indexes</h3>
<p>When a visitor accesses a URL that points to a directory (rather than a specific file), the web server looks for an index file such as <code>index.html</code> or <code>index.php</code>. If no index file is found, the server can either display a listing of all files in that directory or return a 403 Forbidden error. This behavior is controlled by the directory index setting.</p>
<h3>Security Considerations</h3>
<p>Enabling directory indexes can expose the contents of your directories to anyone on the internet. This can reveal:</p>
<ul>
<li>Backup files that might contain sensitive information.</li>
<li>Configuration files, scripts, or other application internals.</li>
<li>Uploaded media and documents you may not want publicly browsable.</li>
</ul>
<div class="alert alert-warning">For security, it is strongly recommended to disable directory indexes on production websites. Only enable them on directories where you intentionally want to provide a file listing.</div>
<h3>Disabling Directory Indexes via .htaccess</h3>
<p>Add the following line to your <code>.htaccess</code> file in <code>public_html</code>:</p>
<pre><code>Options -Indexes</code></pre>
<p>This tells the server to return a 403 Forbidden error instead of listing directory contents when no index file exists.</p>
<h3>Enabling Directory Indexes</h3>
<p>If you specifically want to allow directory listing (for example, a downloads folder), add this to the <code>.htaccess</code> file in that specific directory:</p>
<pre><code>Options +Indexes</code></pre>
<h3>Setting a Custom Index File</h3>
<p>You can control which files the server treats as index files and their priority order:</p>
<pre><code>DirectoryIndex index.php index.html index.htm default.html</code></pre>
<p>The server will try each file in order and serve the first one it finds.</p>
<h3>Using DirectAdmin</h3>
<ol>
<li>Log in to DirectAdmin.</li>
<li>Navigate to <strong>Advanced Features</strong>.</li>
<li>Look for <strong>Directory Indexing</strong> or <strong>Indexes</strong>.</li>
<li>Select the directory and toggle indexing on or off.</li>
<li>Click <strong>Save</strong> to apply the changes.</li>
</ol>
<div class="alert alert-info">Changes to <code>.htaccess</code> take effect immediately. There is no need to restart the web server.</div>
Besoin d'aide ?
Vous ne trouvez pas ce que vous cherchez ? Notre équipe de support est prête à vous aider.
Contacter le support