Home » Php » php – Disable the directory and file listing on web browser.Like we see all listing in source in google chrome

php – Disable the directory and file listing on web browser.Like we see all listing in source in google chrome

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am using PHP as my backend to develop the site, it contains a lot of files and directory. if the structure of my file is visible to the third person it can be easily hacked. So it is necessary to hide those directory form the user view.
I actually search many times on google and found one case

Disable the directory listing shown in the browsers window if there is no any index.html, index.php like files like this screenshot on enabling directory listing.

Image with directory listing enable

I have successfully get rid of this problem just including these lines in the .htaccess file.

Options -Indexes
IndexIgnore *

Now, What I actually want is not to show the directory in the source of the browser after inspecting like this image.

Directory listing showed in source console

But I don’t want to show these directories to the user like https://www.bbc.com/ here I found that only (index) not other directories.

Thanks in advance ..

How to&Answers:

How you enable directory listing depends on the type of server you’re running. See the examples below and click on each server type for more information.

Apache: If apache detects any files in the directory such as:
index.html, index.htm, index.php, welcome.html, default.php, etc., it will load them and not display the list of files.

This list can be configured with the DirectoryIndex directive.

If none of these files are detected, the directory listing will be shown as long as the +Indexes option is set for the directory. For example:

<Directory /usr/local/apache2/htdocs/listme>
  Options +Indexes
</Directory>

Nginx: Add autoindex on; for the desired directory in your config file.

IIS: On the command line, enter:

appcmd set config /section:directoryBrowse /enabled:true