How do I not display the directory list?

Asked

Viewed 1,270 times

0

Hello, so my question is the following, I have a folder called admin and another call general, which is inside the admin. Inside the admin folder I have a file called general.php so far ok, the problem is that if I access it like this:

http://localhost/forum/admin/general/

it enters the general folder and displays everything it has in it, and I don’t want to display anything much less a list of directories would have to avoid this? i tried with htaccess and did not succeed, now if I access so it opens the general file.php

http://localhost/forum/admin/general.php

I tried to use htacess as I had said so:

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^geral(.*)$ geral.php
RewriteRule ^teste(.*)$ teste.php

And it keeps going into the general folder instead of going into the general.php file.

3 answers

1

Super Fast Mode to Solve This Problem

create a blank "index.html" file and place it in the 'general' folder (JOOMLA methodology)

You can solve the problem with index.html blank or by configuring apache in the admin folder, according to the website.

RewriteEngine On 

RewriteRule ^([a-z]+)\/$ $1.php [NC]

This rule should do the following, when accessing the "user friendly" URL it will be redirected to.php.'.

That is to say the client accesses the '/general/ URL the server runs the 'general.php' file'

http://localhost/admin/general/ -> http://localhost/admin/general.php

http://localhost/admin/popcorn/ -> http://localhost/admin/popcorn.php

Alias recommend the answer of Leo Letto and put also:

Options All -Indexes 
  • It’s a little impractical to keep creating an index.html in each folder, don’t think it would be easier to use htaccess?

  • You’re right I’m researching and I’ll edit my answer.

1


Add this line at the beginning of your htaccess and you’re done

Options All -Indexes 
  • That answer was very helpful, thank you Leo!

1

I recommend the following readings:

Blocking Apache directory lists here you need to edit the httpd.conf or apache.conf file and edit the code so it looks like the following:

<Directory "/var/www/htdocs">
    Options +indexes MultiViews
    AllowOverride None
    Order from all
    Allow from all
</Directory> 

and

Preventing file and directory listing with . htaccess (Apache)

in this case you can choose to put the following code in . htaccess

## Impedindo a listagem de qualquer arquivo e diretório
Options -Indexes

or going a little further and preventing only a few extensions from being blocked from listing example:

## Impedindo a listagem do próprio de arquivos .jpg e png
IndexIgnore .jpg, .png

Browser other questions tagged

You are not signed in. Login or sign up in order to post.