0

I have the following folder structure:

+users
   -adduser.php
   -viewuser.php

When a visitor navigates to example.com/users it's showing the folder structure. I need to restrict visitors ability to see the file listing, either by hiding it or removing it. How can I do that in php?

Cyril Graze
  • 3,881
  • 2
  • 21
  • 27
  • You can disable the indexes as per [this other SO post](https://stackoverflow.com/questions/2530372/how-do-i-disable-directory-browsing), but depending on what's in that folder, it might be better to put it outside the webroot all together. – Jonnix Jul 04 '17 at 10:23
  • @JonStirling but in part of developing we have folders right if every thing is in root its not understandable – Pearl Farquhar Jul 04 '17 at 10:24
  • Sorry, can't work out what you're trying to say in your comment. – Jonnix Jul 04 '17 at 10:26
  • read about .htacces file... it will help you to create dummy url for every folder structure url. The your is defined by you but it will internally redirect to require page & url show the dummy url – Ashu Jul 04 '17 at 10:51
  • Rewrote the question and title for clarity and grammar – Cyril Graze Jul 04 '17 at 21:18

3 Answers3

0

You can create a .htaccess file on root folder with following;

RewriteEngine on
Redirect 301 /users http://www.example.com/404.html

Then you just need to create 404.html in your website and change example.com with your domain.

Now your /users path will redirect to 404.html.

Ece
  • 148
  • 9
0

You can add the following to your Apache virtual host file:

<Directory "path_to_folder">
    Options -Indexes
</Directory>

The above rule will disallow directory listing. It was suggested in this post: Using .htaccess, prevent users from accessing resource directories, and yet allow the sourcecode access resources

Nadir Latif
  • 3,690
  • 1
  • 15
  • 24
0

If you don't want to (or can't) deal with Apache configuration, create an empty file named index.html (or index.php if you prefer) in your users folder.

kmoser
  • 8,780
  • 3
  • 24
  • 40