Directory listing in Apache
Directory listing in Apache:
- Web servers always look for document index whenever the client request to view the directory, index file which will be under all the directory.
- While using apache configuration it will show a 404 error.
REMOVING WELCOME PAGE:
Apache will display the welcome page to the clients if the document index not found on the directory. remove the welcome page by deleting the welcome page configuration file. Otherwise it will show the 404 error.
Command to remove the welcome page:
| rm -rf /etc/httpd/conf.d/welcome.conf |
|---|
ADDING the virtual Host:
Add virtual host like below, virtual host should contain the Directory directive and All Indexes directive that will allow the web server to list the files in the directory. Replace with our domain or ip address and also replace /var/www/kr directory.
Commands :
- Mkdir /var/www/kr
- Nano /var/www/kr
Restart the Apache service.
- Systemctl restart httpd
Ping our ip address with the directory path.
https:// 192.151.147.30 /var/www/kr.
Then see the results of the indexing list. Thus, the main purpose of listing the directory of apache is to Enable files and directory listing. Sometimes it's useful to enable files and directory listing (or indexing) to allow users viewing and downloading all the files within a directory.
The results of indexing result have to come Like this,
Error result .
The above is Enabling the Directory listing in Apache.
Disabling the directory list in Apache:
Edit the config file.
| $ sudo vi /etc/httpd/conf/httpd.conf |
|---|
Edit and give Allowoveride all
|
<Directory /var/www/html/> Options Indexes FollowSymLinks AllowOverride All </Directory> |
|---|
You have existing .htaccess file,make a backup of it as follows
| cp /var/www/html/kr/.htaccess /var/www/html/kr/.htaccess.backup |
|---|
Then you can open (or create ) it in the particular directory for modification using your favorite editor, and add the line below to turn off Apache directory listing
| Options - fields |
|---|
Restart the Apache service.
| #Systemctl restart httpd |
|---|