Hide directory contents from showing when accessing the URL directly – Managing your servers can streamline the performance of your team by allowing them to complete complex tasks faster. Plus, it can enable them to detect problems early on before they get out of hand and compromise your business. As a result, the risk of experiencing operational setbacks is drastically lower.
But the only way to make the most of your server management is to perform it correctly. And to help you do so, this article will share nine tips on improving your server management and fix some problem about apache-2.2, .htaccess, directory-listing, rewrite, .
On my site, if you browse to
http://example.com/images/ the contents of the entire directory are shown like so:
How can I make it so that this doesn’t happen?
Can I create an
.htaccess file in that directory? Or is there a better way? I really want to block directory listing for the entire site (i.e. every directory on that site).
I figure it’s either something that has to be done in Apache or using an global
.htaccess file and placing it in the
public_html folder, perhaps?
I diverted this using an
index.php file, but I still feel that security is an issue here, how can I fix this permanently?
Depending on how your
<directory> directives are defined, you have a couple of options.
For that directory,
Options -Indexes will turn that off. This can be done anywhere in the httpd.conf file to disable that sort of thing.
Also, in an .htaccess file in that specific directory you can place
IndexIgnore * will still produce the list but hide all the contents. A bit hacky, but if you can’t modify httpd.conf can work in a pinch.
You need to disable directory browsing. You can do that for the whole server by modifying
httpd.conf, or you can do it in a directory of your choice by using a
In both cases, look for the line that begins with
Options and some other words; if it contains
Indexes, change it to
-Indexes; if it doesn’t contain it, add it to the line.
If there is no
Options directive, just add
Options -Indexes, and that’s all.