InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Apache tutorials

  • AWStats on Ubuntu
  • ApacheBench - load testing
  • Auth to a location or directory
  • Block directory access using htaccess 404
  • Different expire Headers for multiple images
  • Disable directory listing
  • List loaded modules
  • Log Content-Type in access log
  • Log latency and host in apache log
  • Monitoring using mod_status
  • Python to analyze bots in logs
  • Remove php extension from url
  • egrep and access log
  • log custom data in apache access log
  • mod_rewrite
  • top IP list from access log
 
  • Home
  • > Tutorials
  • > Web Development
  • > Apache

Disable directory listing in apache

By admin on Nov 14, 2015

Apache 2.4 on Ubuntu Linux has directory listing enabled by default. In case you are upgrading from apache 2.2 or creating a new site, you may want to disable it. We’ll use Ubuntu linux for the purpose of this tutorial.

Directory listing example

To see directory listing on a new Apache default installation on Ubuntu linux follow these steps:

$ sudo mkdir /var/www/html/foo
$ sudo touch /var/www/html/foo/file1.txt

Now hit the browser with url /foo. You should see something like this:
apache-directory-listing-example

Disable directory listing

To disable directory listing add the following config lines to you custom Apache conf file:

<Directory /var/www/>
  Options -Indexes
  Options +FollowSymLinks
  AllowOverride None
  Require all granted
</Directory>

Also make sure you config file is included in /etc/apache2/apache2.conf. It is a good idea to keep your config changes in a separate config file. That way future upgrade won’t impact your config. After the change, restart apache. Here is how a directory url will look like in Chrome after this change:
apache-directory-listing-forbidden-example

Note that your config and directory location may be different from this example. You may need to follow the instructions appropriately.

Suggested posts:

  1. Block directory access using htaccess 404
  2. PHP sort associative array using custom compare function
  3. Why and how to log Content-Type in apache access log
  4. How to use ssh port forwarding to surf a site from different location
  5. php preg_match – greedy and lazy regex examples
  6. Ubuntu – how to find boot autostart status of a service
  7. Linux – Yesterday’s Date in YYYYMMDD format
  8. How to install and monitor memcache for php on Ubuntu Linux
Share this article: share on facebook share on linkedin tweet this submit to reddit
| Tagged Apache, Linux, Ubuntu Linux, Web Development
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress