Directory List

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rasspass
Forum Newbie
Posts: 4
Joined: Mon Mar 14, 2011 12:20 pm

Directory List

Post by rasspass »

When the default file such as index.html or index.php is missing from the localhost/testsite then all other files within the testsite folder is displayed on the browser. How can I prevent it so it will not show the contents of the directory? Your help is appreciated in advance.
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: Directory List

Post by cpetercarter »

Does your site run on an Apache server? If so, and the server is configured to allow you to use .htaccess files, place an .htaccess file in your root directory with this text:
[syntax]Options -Indexes[/syntax]
or add it to your existing .htaccess file if you have one. Further details here.
Or, simply ensure that you always have an index.html file in every directory. If you have no substantive content to display, you can just display a message, or redirect users to your main site page.
Post Reply