httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bo Berglund <bo.bergl...@gmail.com>
Subject [users@httpd] Re: How to block Apache2 from showing dir lists on Ubuntu 16.04 server...
Date Mon, 11 Mar 2019 10:16:19 GMT
On Mon, 11 Mar 2019 09:12:28 +0100, Bo Berglund
<bo.berglund@gmail.com> wrote:

>If I enter an URL ending with a directory name Apache throws up a list
>of all of the files inside the directory which is NOT what I want.
>I have created a php command to create the display of the dir content
>which works just fine on my webhosting server but not on the ubuntu 16
>server.
>
>This is what I have in my .htaccess file in this dir:
>
>require valid-user
>Options -Indexes
>DirectoryIndex dirlist.php
>
>But notwithstanding this Apache2 does not run the dirlist.php command
>file to get the properly formatted list.
>
>If I explicitly run the url ending with dirlist.php it works as
>expected and I get my formatted directory list. But I want this to
>happen also if the URL is just the directory itself.
>
>So how can I make Apache NOT create the file list but instead run the
>dirlist.php command?

I did a workaround by changing the name of dirlist.php to index.php.
This makes Apache use this file as the renderer if the URL lacks the
file specification.
So this solves the problem for the directories which do have an
index.php inside.
But what to do for intermediate directories which are not supposed to
be shown at all? I REALLY want Apache to show a "Forbidden" page
rather than the list of files and dirs in the directory of the URL.

>I even went as far as editing the
>/etc/apache2/sites-available/000-default.conf file and adding this to
>the end of the directory block:
>
>  <Directory "/var/www/html">
>      AuthType Basic
>      AuthName "Restricted Content"
>      AuthUserFile /etc/apache2/private.htpasswd
>      Require valid-user
>      #Added to block dir listing and allow .htaccess to work
>      AllowOverride All
>      Options -Indexes
>  </Directory>
>
>Then sudo service apache2 restart
>

Question remains, why does this not work?

Note that I have not added any virtual hosts or anything, Apache is
straight out of the box except for Subversion and it has enabled the
default site /var/www/html, which is the one I am trying to get
working properly.

-- 
Bo Berglund
Developer in Sweden


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message