Search Our Database
How to enable/disable Directory Listing via Command Line (CLI)
Introduction
Directory listing displays the contents of a directory when no index file is present. By modifying the .htaccess file, you can enable or disable this feature for security purposes or to provide easier file access. This is particularly important for controlling access to files on your server. This guide explains how to enable or disable directory listing using the .htaccess file, allowing you to manage file visibility and security in web directories.
Prerequisite
- SSH access to server
- Access to your website’s root directory
- Ability to edit the .htaccess file
- Basic understanding of Apache web server configurations.
Step-by-step guide
Step 1: Access to your server
- Access your server via SSH. If you are non-having control panel like DirectAdmin or cPanel, you may continue Step 2 once connected.
Else, if you are having control panel, you will need to switch to your control panel user before continuing on Step 2.sudo su <user>
Step 2: Locate and navigate to website root directory
- Locate your website root directory and navigate to the directory by using cd command.
For the server which not having control panel, the path typically will be as below:cd /var/www/html
For the server which having control panel, the path typically will be as below:
cd /home/<username>/<domain>/public_html/
Step 3: Verify if .htaccess existed
- Once you have reached the website root directory, you will need to verify if the .htaccess file existed.
The.htaccess file is a hidden file, you may use command below to show it.ls -la | grep "htaccess"
- If the .htaccess does not exist, you may run the command below to create
touch .htaccess
chmod 644 .htaccess
Step 4: Edit the .htaccess file to redirect the site
- To edit the .htaccess file, we will be using vi command as below.
vi .htaccess
- Once you have entered editor screen, press i to enable the edit mode and adding lines as below.
To enable directory listing:Options +Indexes
To disable directory listing:
Options -Indexes
- Then press ESC and enter :wq to save.
:wp
Step 5: Verify the result
Conclusion
By going through this guidance, you will be able to enable or disable directory listing using .htaccess, enhancing control over your server’s file visibility and security.
For additional assistance or if you encounter any issues, please contact our support team at support@ipserverone.com.